-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Open
Description
Version
- Phaser Version: 3.90.0
- Operating system: Every single one
- Browser: All of the browser
Description
While phaser.d.ts does declare Phaser.Types.Scenes.SceneInitCallback, Phaser.Types.Scenes.ScenePreloadCallback and Phaser.Types.Scenes.SceneCreateCallback as the types of Scene.init, Scene.preload and Scene.create, said class does not declare any of these methods.
This results in poorer developer DX due to a lack of JSDoc hover info, as well as not appearing in the list of inherited methods from TypeScript (one cannot use override modifiers, for instance).
Example Test Code
class MyScene extends Phaser.Scene {
// Produces type errors because Phaser.Scene doesn't define an `init` method to override
public override init(): void {
console.log("Hello from Phaser!");
}
}Additional Information
I have 2 potential ways to update the typings:
- Amend
Phaser.Sceneto contain properties with the correspondingly typed callbacks, keeping everything else there. This would be simple, but property-style methods look slightly uglier inside IDEs. - Move the declarations directly inside
Phaser.Sceneitself and edit the callback types to reference that instead.
// opt 1
declare module Phaser {
class Scene {
init?: SceneInitCallback;
preload?: ScenePreloadCallback;
create?: SceneCreateCallback;
}
namespace Types {
namespace Scenes {
type SceneInitCallback = (this: Scene, data: object) => void;
type ScenePreloadCallback = (this: Scene, data: object) => void;
type SceneInitCallback = (this: Scene) => void;
}
}
}// opt 2
declare module Phaser {
class Scene {
init(this: Phaser.Scene, data: object): void;
preload(this: Phaser.Scene, data: object): void;
create(this: Phaser.Scene): void;
}
namespace Types {
namespace Scenes {
type SceneInitCallback = Phaser.Scene['init'];
type ScenePreloadCallback = Phaser.Scene['preload'];
type SceneCreateCallback = Phaser.Scene['create'];
}
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels