ScalablyTyped / Converter

Typescript to Scala.js converter
https://scalablytyped.org
GNU General Public License v3.0
219 stars 43 forks source link

Naming conflicts with scala-js-dom #436

Open AlexITC opened 2 years ago

AlexITC commented 2 years ago

I got into a weird situation, having a TypeScript definition with a model called KeyUsage ended up with a wrongly generated type org.scalajs.dom.KeyUsage.

I'm yet to create a reproducible example.

oyvindberg commented 2 years ago

Hey again. thanks for the report.

Just to clarify, you're translating a library which has its own KeyUsage, and it ends up using the one from the DOM instead? Which library and version is this? This may be easy enough or very very hard to fix, depending on what exactly went wrong :)

I'm not shocked to see bugs in this direction honestly, resolving type names in typescript is much harder than you would imagine. Mostly because it has a lot of interaction with interface augmentation, and then there are the global things which are always available even when using modules, and then the module systems themselves. As such, when resolving names, it's fairly common to find more than one type definition.

For now it's very simplistic, the first found type definition is picked. see QualifyReferences. (I see there is logic in the file to perform intersections and to prefer std in some cases, but this line effectively disables that logic. Should definitely be cleaned up)

workaround

a cast and a comment in your code, or some pass to fix the generated code.

AlexITC commented 2 years ago

Just to clarify, you're translating a library which has its own KeyUsage, and it ends up using the one from the DOM instead?

Yes.

Which library and version is this? This may be easy enough or very very hard to fix, depending on what exactly went wrong :)

Unfortunately, it is a private TypeScript library, I'm willing to try preparing a small reproducible example, I just haven't had the time.

a cast and a comment in your code, or some pass to fix the generated code.

Right now, I'm casting the type.

thanks.