OpenAPITools / OpenAPITools/openapi-generator
oneOf enums prone to TS2693: 'AssetStateEnum ' only refers to a type, but is being used as a value here.
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
Generator produced:
export const AssetStateEnum = {
Expected: 'EXPECTED',
Live: 'LIVE',
Retiring: 'RETIRING'
} as const;
export type AssetStateEnum = typeof AssetStateEnum[keyof typeof AssetStateEnum];
if used as:
import {
AssetStateEnum ,
} from 'cmdb-openapi-angular-client';
...
array.includes(AssetStateEnum.Live)
then getting:
TS2693: 'AssetStateEnum ' only refers to a type, but is being used as a value here. [plugin angular-compiler]
openapi-generator version
"@openapitools/openapi-generator-cli": "^2.24.0"
"generator-cli": {
"version": "7.16.0"
}
OpenAPI declaration file content or url
AssetStateEnum:
type: string
oneOf:
- enum: [EXPECTED]
description: >-
...
- enum: [LIVE]
description: >-
....
- enum: [RETIRING]
description: >-
...
i.e. leveraging new 7.16 feature that allows to describe enum literals using the oneOf trick.
Steps to reproduce
Define enum schema using oneOf and generate Angular client using 2.24.0 generator.
Suggest a fix
Consider exporting the generated type and the object under different names, e.g. adding Type suffix to type such as:
export type AssetStateEnumType = typeof AssetStateEnum[keyof typeof AssetStateEnum];
to help disambiguate the import in the use site.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue with the provided AssetStateEnum oneOf schema and the Angular client generator version 7.16.0. Then trace the generator's TypeScript Angular enum output and related tests, if present. Done means the generated enum value can be imported and used without TS2693 while the corresponding type remains usable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100