You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The problem lies in the interface Root extends RootType statement which results in the following error being emitted by tsc:
An interface can only extend an object type or intersection of object types with statically known members.(2312)
and at least in vscode intellisense doesn't pickup the type correctly.
I couldn't find any macro attributes that would result in the correct TS output but maybe I'm missing something. Other than manually changing the TS Root definition to use type instead of interface a workaround is to change the Rust Root to an enum:
I get the same behavior with both 0.5.4 and 27d6982.
If this is truly a bug and not a user error I can try to have a peek under the hood at some point, but that being said I don't have a ton of experience with Rust macros so it will likely take some time 😀
The text was updated successfully, but these errors were encountered:
vuorioi
changed the title
Bug: structs with flattened enums produce invalid TS
Bug: structs with flattened enums produces invalid TS
Aug 15, 2024
vuorioi
changed the title
Bug: structs with flattened enums produces invalid TS
Bug: structs with flattened enums produce invalid TS
Aug 15, 2024
This is unfortunately a bug :-(. The original tsify author was not keen on switching interface to type, but it does make extending union types impossible...Probably enums should be written as types and struct should be written as interface.
One possible consequence is an interaction with generics. Since interfaces can handle generics better than types in typescript.
I would welcome a PR that tested out using type for generating the type of an enum (and maybe a flag to use an interface instead?)
I run into an issue regarding the types generated for structs with flattened enums.
For example when I define:
the following TS gets generated:
The problem lies in the
interface Root extends RootType
statement which results in the following error being emitted bytsc
:and at least in vscode intellisense doesn't pickup the type correctly.
I couldn't find any macro attributes that would result in the correct TS output but maybe I'm missing something. Other than manually changing the TS
Root
definition to usetype
instead ofinterface
a workaround is to change the RustRoot
to an enum:which yields a working TS definition, albeit at the expense of the Rust side ergonomics:
I get the same behavior with both 0.5.4 and 27d6982.
If this is truly a bug and not a user error I can try to have a peek under the hood at some point, but that being said I don't have a ton of experience with Rust macros so it will likely take some time 😀
The text was updated successfully, but these errors were encountered: