dotansimha / dotansimha/graphql-code-generator
`enumsAsConst` - enum name conflicts with type name
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 1.4k
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 23
Description
### Describe the bug
When using `enumsAsConst: true` in the config, the name generated for the const object conflicts with the name generated for the type:
```typescript
// generated file
export const IconProvider = {
FontAwesome: 'FONT_AWESOME',
MaterialUi: 'MATERIAL_UI',
} as const
export type IconProvider = typeof IconProvider[keyof typeof IconProvider] // ESLint: 'IconProvider' is already defined.(@typescript-eslint/no-redeclare)
```
I tried with & without the `typesSuffix` config and it didn't solve it:
```typescript
export const IconProviderSuffix = ...
export type IconProviderSuffix = ...
```
### Your Example Website or App
none, sorry
### Steps to Reproduce the Bug or Issue
1. Go to the config file and use the following flag:
`enumsAsConst: true`
2. Go to the generated file and see the conflict
### Expected behavior
The names shouldn't overlap.
Maybe the `const enum` (JS object) shouldn't be treated as a type in order to allow a `typesSuffix` that would only be appended to the real type.
### Screenshots or Videos
_No response_
### Platform
System:
OS: Linux 5.15 Ubuntu 20.04.5 LTS (Focal Fossa)
Binaries:
Node: 16.14.2 - /usr/local/bin/node
Yarn: 1.22.18 - /usr/local/bin/yarn
npm: 8.7.0 - /usr/local/bin/npm
Browsers:
Chrome: 106.0.5249.91
npmPackages:
"@graphql-codegen/cli": "2.6.2",
"@graphql-codegen/typescript": "2.4.11",
"@graphql-codegen/typescript-operations": "2.4.0",
typescript: 4.5.5 => 4.5.5
### Codegen Config File
```yml
overwrite: true
schema: "http://localhost:4000/graphql"
documents: "./graphql/**/*.gql"
generates:
graphql/generated/graphqlGen.tsx:
plugins:
- "typescript"
- "typescript-operations"
config:
enumsAsConst: true
# typesSuffix: "Type"
```
### Additional context
_No response_
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.