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

Generated enum type definitions don't compile #69

Closed
DanielRose opened this issue Dec 7, 2021 · 0 comments · Fixed by #70
Closed

Generated enum type definitions don't compile #69

DanielRose opened this issue Dec 7, 2021 · 0 comments · Fixed by #70

Comments

@DanielRose
Copy link
Contributor

2.7.0 (and 2.8.0) added enum value exports. However, the generated code is incorrect and does not compile. For example, in the example-usage/generated/index.d.ts it will result in the following error:

error TS1254: A 'const' initializer in an ambient context must be a string or numeric literal or literal enum reference.

The reason it currently compiles in example-usage, is that example-usage skips type checking the declaration files (tsconfig.json contains "skipLibCheck": true).

The generated code is:

export declare const enumCacheControlScope = {
  PUBLIC: 'PUBLIC',
  PRIVATE: 'PRIVATE',
} as const

The correct code would be to use a declaration instead of an initializer:

// Variant 1
export declare const enumCacheControlScope: {
  PUBLIC: 'PUBLIC',
  PRIVATE: 'PRIVATE',
}

// Variant 2 - the values are not really readonly, but should be handled as such
export declare const enumCacheControlScope: {
  readonly PUBLIC: 'PUBLIC',
  readonly PRIVATE: 'PRIVATE',
}
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

Successfully merging a pull request may close this issue.

1 participant