Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support shared properties of type unions #105

Open
sonygod opened this issue Dec 2, 2021 · 5 comments
Open

Support shared properties of type unions #105

sonygod opened this issue Dec 2, 2021 · 5 comments
Labels
enhancement New feature or request

Comments

@sonygod
Copy link

sonygod commented Dec 2, 2021

ts.AnyOf issue.

some gen class have some fields like

    	var geometry : ts.AnyOf2<A,B>;

        geometry .AProperty=1;//current will throw error.
      
       geometry.BProperty=2;//current will throw error.

//is possible to do something like that?

@haxiomic
Copy link
Owner

haxiomic commented Dec 2, 2021

I’m not sure I follow - could you explain a bit more? What does the source typescript look like?

Do you mean those properties are shared between types A and B and should be accessible within the AnyOf?

I have a plan for this but it requires macros, it’s in the roadmap but less critical than other features

@sonygod
Copy link
Author

sonygod commented Dec 3, 2021

     Do you mean those properties are shared between types A and B and should be accessible within the AnyOf?

yes ,I mean those properties are shared between types A and B,because we have a project use native js ,there are lots of these

style something like

         class  SomeClass {
           var geometry : ts.AnyOf2<A,B>;
     }

        var sc=new SomeClass ();

       sc.geometry .AProperty=1;
   
       var sc2=new SomeClass ();

      sc.geometry .BProperty=1;

I convert to haxe I have to write lots of cast ugly code ...

   cast (sc.geometry,A) .AProperty=1;         
   cast (sc.geometry,B) .BProperty=1;

@haxiomic
Copy link
Owner

haxiomic commented Dec 3, 2021

Agreed, it can be solved with a type building macro which is on the roadmap
I'll rename the issue and leave it open

btw this also works

sc.asType0.AProperty = 1;
sc.asType1.BProperty = 1;

@haxiomic haxiomic changed the title ts.AnyOf issue. Support shared properties of type unions Dec 3, 2021
@haxiomic haxiomic added the enhancement New feature or request label Dec 3, 2021
@sonygod
Copy link
Author

sonygod commented Dec 4, 2021

there is more complex in three.js

              class  SomeClass {
           var geometry : ts.AnyOf2<AParent,BParent>;
     }
      
        var sc=new SomeClass ();

       sc.geometry .AChildClasssProperty=1;//native js  direct support  child's property.

Mesh.hx

 extern class Mesh extends Object3D

var material : ts.AnyOf2<Material, Array<Material>>;


                myobject .material.color.set(iColor);//base Material have no color property 
                  myobject.material.needsUpdate = true;//base Material have no needsUpdate property 

@sonygod
Copy link
Author

sonygod commented Jan 14, 2022

@haxiomic ,dts2hx 0.18.1 seem support this ? I will close this issue.

three.js 0.135

seem resolution this issue.

    Line<TGeometry, TMaterial>   and    extern class Mesh<TGeometry, TMaterial> 

    var geometry : TGeometry; 

	var material : TMaterial;

@sonygod sonygod closed this as completed Jan 14, 2022
@sonygod sonygod reopened this Jan 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants