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

Clean the TypeDef and report an bug

Open orblazer opened this issue 7 years ago • 2 comments
trafficstars

Hello, I have an question : When the type is generate correctly we can move the types on phaser project for automaticly detect ?

I have this propositions for clean the TypeDef :

  1. Move the type declaration in specific namespace
  2. Merge object in same parent properties (look example n°1)
  3. ~~Trim the description (look example n°2)~~ (Fixed on this PR #9)

I have found potential bugs in the TypeDef :

  1. The functions in namespace (like Actions) dont have prefix export
  2. In the description the optional param is not defined (example in example n°2)
  3. The description doesn't declare @return param
  4. ~~The module phaser is not declared.~~ (This PR fix that #10)

Example n°1

In type JSONCamera you have :

declare type JSONCamera = {
    [...]
    /**
     * The bounds of camera
     */
    bounds: object;
    /**
     * The horizontal position of bounds of camera
     */
    "bounds.x": number;
    /**
     * The vertical position of bounds of camera
     */
    "bounds.y": number;
    /**
     * The width of the bounds of camera
     */
    "bounds.width": number;
    /**
     * The height of the bounds of camera
     */
    "bounds.height": number;
}

but we can clean the type for this :

declare type JSONCamera = {
    [...]
    /**
     * The bounds of camera
     */
    bounds: {
        /**
         * The horizontal position of bounds of camera
         */
        x: number;
        /**
         * The vertical position of bounds of camera
         */
        y: number;
        /**
         * The width of the bounds of camera
         */
        width: number;
        /**
         * The height of the bounds of camera
         */
        height: number;
    };
}

Example n°2

In namespace Actions you have this description :

/**
 * Takes an array of Game Objects, or any objects that have a public `angle` property,
 * 
 * and then adds the given value to each of their `angle` properties.
 * 
 * 
 * 
 * The optional `step` property is applied incrementally, multiplied by each item in the array.
  * 
  * 
 * 
 * To use this with a Group: `Angle(group.getChildren(), value, step)`
 * @param items The array of items to be updated by this action.
 * @param value The amount to be added to the `angle` property.
 * @param step This is added to the `value` amount, multiplied by the iteration counter. Default 0.
 * @param index An optional offset to start searching from within the items array. Default 0.
 * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1.
 */
function Angle<G extends Phaser.GameObjects.GameObject[]>(items: G, value: number, step?: number, index?: integer, direction?: integer): G;

but you can clean for that :

/**
 * Takes an array of Game Objects, or any objects that have a public `angle` property,
 * and then adds the given value to each of their `angle` properties.
 * 
 * The optional `step` property is applied incrementally, multiplied by each item in the array.
 *
 * To use this with a Group: `Angle(group.getChildren(), value, step)`
 *
 * @param items The array of items to be updated by this action.
 * @param value The amount to be added to the `angle` property.
 * @param step This is added to the `value` amount, multiplied by the iteration counter. Default 0.
 * @param index An optional offset to start searching from within the items array. Default 0.
 * @param direction The direction to iterate through the array. 1 is from beginning to end, -1 from end to beginning. Default 1.
 */
function Angle<G extends Phaser.GameObjects.GameObject[]>(items: G, value: number, step?: number, index?: integer, direction?: integer): G;

orblazer avatar Mar 30 '18 12:03 orblazer

Add bug :

  • The generic type on callback is not right. Current version :
declare type EachListCallback<I extends *> = (item: any, ...args: any[])=>void;

declare type EachMapCallback<E extends *> = (key: string, entry: any)=>void;

declare type EachSetCallback<E extends *> = (entry: any, index: number)=>void;

Whanted version (+ the return value need nullable boolean) :

declare type EachListCallback<I extends any> = (item: I, ...args: any[])=>void;

declare type EachMapCallback<E extends any> = (key: string, entry: E)=>void;

declare type EachSetCallback<E extends any> = (entry: E, index: number)=>void;

orblazer avatar Apr 03 '18 14:04 orblazer

I have noticed that for GameConfig declaration you are missing render property as the whole object also i am not sure if that property shouldn't be of type RendererConfig it has some similar properties like pixelArt, roundPixels, autoResize and some are on GameConfig like backgroundColor.

I have also noticed this one for optimization:

"render.powerPreference"?: string;

could be

"render.powerPreference"?: 'high-performance' | 'low-power' | 'default';

This one also seems to be wrong declare type ColorObject = ()=>void;

Xesenix avatar May 31 '18 21:05 Xesenix