diff --git a/README.md b/README.md index 7c2ac54a..5b69a6b4 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,14 @@ const scene = useScene(); > [!WARNING] > Don't use this hook if you start multiple Scenes. +To specify a Scene class in TypeScript: + +```ts +class MyScene extends Phaser.Scene {} + +const scene = useScene(); +``` + ## Release Release is automated with [Release Please](https://github.com/googleapis/release-please). diff --git a/src/helpers/scene.test.ts b/src/helpers/scene.test.ts index 75b03319..d1e4351c 100644 --- a/src/helpers/scene.test.ts +++ b/src/helpers/scene.test.ts @@ -8,8 +8,15 @@ afterEach(() => { setScene(undefined as unknown as Scene); }); -it('sets and gets scene', () => { - expect(getScene()).toEqual(undefined); - expect(setScene(scene)).toEqual(undefined); - expect(getScene()).toEqual(scene); +describe('getScene', () => { + it('gets scene', () => { + expect(getScene()).toEqual(undefined); + }); +}); + +describe('setScene', () => { + it('sets scene', () => { + expect(setScene(scene)).toEqual(undefined); + expect(getScene()).toEqual(scene); + }); }); diff --git a/src/helpers/scene.ts b/src/helpers/scene.ts index 57f1c136..4f8a42dc 100644 --- a/src/helpers/scene.ts +++ b/src/helpers/scene.ts @@ -2,8 +2,8 @@ import type { Scene } from 'phaser'; let _scene: Scene; -export function getScene() { - return _scene; +export function getScene() { + return _scene as Type; } export function setScene(scene: Scene) { diff --git a/src/hooks/useScene.test.ts b/src/hooks/useScene.test.ts index 7dc5c285..1bdcb6c7 100644 --- a/src/hooks/useScene.test.ts +++ b/src/hooks/useScene.test.ts @@ -15,3 +15,7 @@ it('returns scene', () => { expect(useScene()).toEqual(scene); expect(mockedGetScene).toHaveBeenCalledTimes(1); }); + +it('returns undefined', () => { + expect(useScene()).toEqual(undefined); +}); diff --git a/src/hooks/useScene.ts b/src/hooks/useScene.ts index 4130fc2a..0f99a329 100644 --- a/src/hooks/useScene.ts +++ b/src/hooks/useScene.ts @@ -1,3 +1,5 @@ +import type { Scene } from 'phaser'; + import { getScene } from '../helpers'; /** @@ -7,6 +9,6 @@ import { getScene } from '../helpers'; * * @returns Phaser.Scene */ -export function useScene() { - return getScene(); +export function useScene() { + return getScene(); } diff --git a/src/types/utils.ts b/src/types/utils.ts index 2c0042c2..abe99d3d 100644 --- a/src/types/utils.ts +++ b/src/types/utils.ts @@ -1,3 +1,3 @@ -export type RecursivePartial = { - [P in keyof T]?: RecursivePartial; +export type RecursivePartial = { + [Property in keyof Type]?: RecursivePartial; };