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

Use const enums in TS generator #610

Open
DeTeam opened this issue Oct 2, 2018 · 1 comment
Open

Use const enums in TS generator #610

DeTeam opened this issue Oct 2, 2018 · 1 comment
Labels
🙏 help-wanted 🎉 feature New addition or enhancement to existing solutions

Comments

@DeTeam
Copy link
Contributor

DeTeam commented Oct 2, 2018

Currently graphql enums are modelled in TS using normal enums. In order to not have any runtime consequences we can switch to const enum (https://www.typescriptlang.org/docs/handbook/enums.html#const-enums)

@ghost ghost added the 🎉 feature New addition or enhancement to existing solutions label Oct 2, 2018
@JakeDawkins JakeDawkins removed 🤖 component - codegen related to the codegen core packages labels Mar 11, 2019
@LinusU
Copy link

LinusU commented Apr 23, 2020

(crossposting from #1827)


Note that issues can arise when using const enums if care is not taken, even the TypeScript PM suggests that:

Sure, they can be great for the internals of a library to get some speed improvements, but they generally shouldn't be used outside of that scope.

ref: facebook/create-react-app#4837 (comment)


The TypeScript team development lead has also chimed in and said that using string unions is the best approach for this project:

From a TypeScript language perspective, this is a big improvement. 👍

ref: #1750 (review)


Also, const enums doesn't work with Babel which many people are using to transpile their TypeScript code...

ref: https://babeljs.io/docs/en/babel-plugin-transform-typescript#caveats

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙏 help-wanted 🎉 feature New addition or enhancement to existing solutions
Projects
None yet
Development

No branches or pull requests

4 participants