phaser3-docs icon indicating copy to clipboard operation
phaser3-docs copied to clipboard

Bugs in Typescript definitions

Open fant0m opened this issue 7 years ago • 9 comments
trafficstars

  1. "module 'phaser' has no default export" - probably it should have one
  2. optional parameters has wrong syntax - e.g. GameConfig type has property "?parent": any;, correct syntax parent?: any;

fant0m avatar Apr 01 '18 10:04 fant0m

Regarding your second point...

There's a chunk of code at https://github.com/photonstorm/phaser3-docs/blob/master/tsgen/src/Parser.ts#L659 that addresses this for parameters, but not for properties of objects, you could plop the following in just after https://github.com/photonstorm/phaser3-docs/blob/master/tsgen/src/Parser.ts#L611 to fix it (I tested and it works)...

if(propDoc.name.startsWith('?')) {
    console.log(`Removing ? from ${propDoc.name} in ${doclet.longname}.`);
    propDoc.optional = true;
    propDoc.name = propDoc.name.slice(1);
}

...however I think they'll probably want to address this in the jsdoc in the main repo, that property in your comment comes from * @property {*} [?parent=null] - [description], I don't think [?parent=null] is valid jsdoc, since the [] already denotes it as being optional.

I'm going to submit a PR on the main repo with those docs updated and see what they say.

erd0s avatar Apr 02 '18 10:04 erd0s

Hi - a ? at the start of a type in jsdoc means it can be nullable: http://usejsdoc.org/tags-type.html

photonstorm avatar Apr 02 '18 11:04 photonstorm

Oh whoops! OK I'll delete my PR on the main repo, so do you think the above solution?

erd0s avatar Apr 02 '18 11:04 erd0s

Oh wait that would be at the start of the type itself, not the name of the variables/property, I'll go ahead and reopen the PR. Just curious, is there a reason to chose one over the other? I understand that one will be undefined and one null, but is there any convention like "in user supplied objects we use optional, in objects coming from the library we use nullable"? Or just whatever?

erd0s avatar Apr 02 '18 11:04 erd0s

To be clear of the difference I'm talking about in the above comment:

  • Nullable - @property {?boolean} canvasBitBltShift
  • Optional - @property {number} [zoom=1]

erd0s avatar Apr 02 '18 11:04 erd0s

Yes, for nullable types the question mark goes at the start of the data-type, not the property name. There is also ! which means 'not nullable'. A nullable type is one in which it's safe for the property to be set to null, or the property starts out as null and then gains its type later on. This happens often in v3 as properties mapping to systems are created later in the boot stage.

photonstorm avatar Apr 03 '18 12:04 photonstorm

I'm kind of new with phaser. I'm getting a Tyscript compile error when trying to do

game.physics.add.sprite

It says:

physics property does not exist on object 'game'

PhernandoAB avatar Apr 20 '18 08:04 PhernandoAB

It would say the same for JavaScript too, because physics isn’t a property of game. In v3 you shouldn’t ever use game as the route in for anything. Look at the examples for reference.

photonstorm avatar Apr 20 '18 09:04 photonstorm

There seems to be a problem in typescript definitions with the class RenderTexture. It is missing: draw(texture: Phaser.Textures.Texture, frame: Phaser.Textures.Frame, x: number, y: number): void; There are probably some other method signatures missing such as drawFrame. As they get added from webgl or canvas renderer definitions I suspect generator is not picking them up.

mnoga23 avatar Apr 23 '18 21:04 mnoga23