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 for Enums and Namespace Types in Strip-Only Mode #22

Closed
mertcanaltin opened this issue Jul 30, 2024 · 2 comments
Closed

Support for Enums and Namespace Types in Strip-Only Mode #22

mertcanaltin opened this issue Jul 30, 2024 · 2 comments

Comments

@mertcanaltin
Copy link
Member

Hello,

I encountered an issue while using the transformSync function where it appears that enums and namespace types are not supported in strip-only mode. Specifically, the function fails to strip type annotations from enums and namespaces, leading to errors in the transformation process

@marco-ippolito
Copy link
Member

It is by design nodejs/loaders#217

@dionysiusmarquis
Copy link

I just want to leave a quck "workaround", at least for string enums

const Direction = {
  Up = "up",
  Down = "down",
  Left = "left",
  Right = "right",
} as const;
type Direction = (typeof Direction )[keyof typeof Direction ];

Important is as const. This way type Direction will be "up" | "down" | "left" | "right", wich should work pretty much (or maybe axacly?) like a string enum.

Here the same result with a custom helper type

type StringEnum<T extends Record<string, string>> = T[keyof T];
...
type Direction = StringEnum<typeof Direction>;
´´´

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants