BabylonJS / Editor

Community managed visual editor for Babylon.js
http://editor.babylonjs.com/
813 stars 232 forks source link

refactor: improve type safety of inspector properties #399

Closed BradlyBarnacles closed 1 year ago

BradlyBarnacles commented 1 year ago

Links the type of inspector field ("number", "string", "KeyMap" ... ect) to the defaultValue type and options it has. For insance;

@visibleInInspector("sriring", "name", 42, { max: 3 })

would produce an error due to incorrect default value and options.

tthis also helps in ScriptInspector component

julien-moreau commented 1 year ago

@BradlyBarnacles I'm testing right now, I'm also testing that there is no breaking change

julien-moreau commented 1 year ago

Hey @BradlyBarnacles everything works well!! Only "Node" property type is broken. For example:

@visibleInInspector("Node", "Light to track", "sun", {
    allowedNodeType: "Light",
})
public node: DirectionalLight;

Generates the following error

src/scenes/error.ts:10:6 - error TS2345: Argument of type 'MyScript' is not assignable to parameter of type 'Record<"node", string | number | boolean | Texture | Vector2 | Vector3 | Vector4 | Color3 | Color4 | Node>'.
  Types of property 'node' are incompatible.
    Type 'DirectionalLight' is not assignable to type 'string | number | boolean | Texture | Vector2 | Vector3 | Vector4 | Color3 | Color4 | Node'.
      Type 'DirectionalLight' is missing the following properties from type 'Texture': url, uOffset, vOffset, uScale, and 110 more.

10     @visibleInInspector("Node", "Light to track", "sun", {
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11         allowedNodeType: "Light",
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12     })
julien-moreau commented 1 year ago

Also, unfortunately having support of private members is mandatory in order to avoid breaking changes :(

BradlyBarnacles commented 1 year ago

Also, unfortunately having support of private members is mandatory in order to avoid breaking changes :

Cool, will fix that

julien-moreau commented 1 year ago

@BradlyBarnacles hope you are going well! Do you have any news about that feature? It looks awesome to have

BradlyBarnacles commented 1 year ago

@BradlyBarnacles hope you are going well! Do you have any news about that feature? It looks awesome to have @julien-moreau unfortunately i think it might not be possible since the decorator can be added to private properties. Going to have one more look at it but will probably close the pull request