@@ -92,7 +92,7 @@ export class TsVisitor<
92
92
}
93
93
94
94
protected _getTypeForNode ( node : NamedTypeNode ) : string {
95
- const typeAsString = ( node . name as any ) as string ;
95
+ const typeAsString = node . name as any as string ;
96
96
97
97
if ( this . config . useImplementingTypes ) {
98
98
const allTypesMap = this . _schema . getTypeMap ( ) ;
@@ -114,7 +114,16 @@ export class TsVisitor<
114
114
}
115
115
}
116
116
117
- return super . _getTypeForNode ( node ) ;
117
+ const typeString = super . _getTypeForNode ( node ) ;
118
+
119
+ if ( this . config . allowEnumStringTypes === true ) {
120
+ const schemaType = this . _schema . getType ( node . name as any as string ) ;
121
+ if ( isEnumType ( schemaType ) ) {
122
+ return `${ typeString } | ` + '`${' + typeString + '}`' ;
123
+ }
124
+ }
125
+
126
+ return typeString ;
118
127
}
119
128
120
129
public getWrapperDefinitions ( ) : string [ ] {
@@ -193,7 +202,7 @@ export class TsVisitor<
193
202
. export ( )
194
203
. asKind ( 'type' )
195
204
. withName ( this . convertName ( node ) )
196
- . withComment ( ( node . description as any ) as string )
205
+ . withComment ( node . description as any as string )
197
206
. withContent ( possibleTypes ) . string ;
198
207
// return super.UnionTypeDefinition(node, key, parent).concat(withFutureAddedValue).join("");
199
208
}
@@ -211,7 +220,7 @@ export class TsVisitor<
211
220
FieldDefinition ( node : FieldDefinitionNode , key ?: number | string , parent ?: any ) : string {
212
221
const typeString = this . config . wrapEntireDefinitions
213
222
? `EntireFieldWrapper<${ node . type } >`
214
- : ( ( node . type as any ) as string ) ;
223
+ : ( node . type as any as string ) ;
215
224
const originalFieldNode = parent [ key ] as FieldDefinitionNode ;
216
225
const addOptionalSign = ! this . config . avoidOptionals . field && originalFieldNode . type . kind !== Kind . NON_NULL_TYPE ;
217
226
const comment = this . getFieldComment ( node ) ;
@@ -233,7 +242,7 @@ export class TsVisitor<
233
242
! this . config . avoidOptionals . inputValue &&
234
243
( originalFieldNode . type . kind !== Kind . NON_NULL_TYPE ||
235
244
( ! this . config . avoidOptionals . defaultValue && node . defaultValue !== undefined ) ) ;
236
- const comment = transformComment ( ( node . description as any ) as string , 1 ) ;
245
+ const comment = transformComment ( node . description as any as string , 1 ) ;
237
246
const { type } = this . config . declarationKind ;
238
247
return (
239
248
comment +
@@ -246,7 +255,7 @@ export class TsVisitor<
246
255
}
247
256
248
257
EnumTypeDefinition ( node : EnumTypeDefinitionNode ) : string {
249
- const enumName = ( node . name as any ) as string ;
258
+ const enumName = node . name as any as string ;
250
259
251
260
// In case of mapped external enum string
252
261
if ( this . config . enumValues [ enumName ] && this . config . enumValues [ enumName ] . sourceFile ) {
@@ -274,15 +283,15 @@ export class TsVisitor<
274
283
return new DeclarationBlock ( this . _declarationBlockConfig )
275
284
. export ( )
276
285
. asKind ( 'type' )
277
- . withComment ( ( node . description as any ) as string )
286
+ . withComment ( node . description as any as string )
278
287
. withName ( enumTypeName )
279
288
. withContent (
280
289
'\n' +
281
290
node . values
282
291
. map ( enumOption => {
283
- const name = ( enumOption . name as unknown ) as string ;
292
+ const name = enumOption . name as unknown as string ;
284
293
const enumValue : string | number = getValueFromConfig ( name ) ?? name ;
285
- const comment = transformComment ( ( enumOption . description as any ) as string , 1 ) ;
294
+ const comment = transformComment ( enumOption . description as any as string , 1 ) ;
286
295
287
296
return comment + indent ( '| ' + wrapWithSingleQuotes ( enumValue ) ) ;
288
297
} )
@@ -294,17 +303,17 @@ export class TsVisitor<
294
303
if ( this . config . numericEnums ) {
295
304
const block = new DeclarationBlock ( this . _declarationBlockConfig )
296
305
. export ( )
297
- . withComment ( ( node . description as any ) as string )
306
+ . withComment ( node . description as any as string )
298
307
. withName ( enumTypeName )
299
308
. asKind ( 'enum' )
300
309
. withBlock (
301
310
node . values
302
311
. map ( ( enumOption , i ) => {
303
- const valueFromConfig = getValueFromConfig ( ( enumOption . name as unknown ) as string ) ;
312
+ const valueFromConfig = getValueFromConfig ( enumOption . name as unknown as string ) ;
304
313
const enumValue : string | number = valueFromConfig ?? i ;
305
- const comment = transformComment ( ( enumOption . description as any ) as string , 1 ) ;
314
+ const comment = transformComment ( enumOption . description as any as string , 1 ) ;
306
315
307
- return comment + indent ( ( enumOption . name as unknown ) as string ) + ` = ${ enumValue } ` ;
316
+ return comment + indent ( enumOption . name as unknown as string ) + ` = ${ enumValue } ` ;
308
317
} )
309
318
. concat ( ...withFutureAddedValue )
310
319
. join ( ',\n' )
@@ -324,13 +333,13 @@ export class TsVisitor<
324
333
. export ( )
325
334
. asKind ( 'const' )
326
335
. withName ( enumTypeName )
327
- . withComment ( ( node . description as any ) as string )
336
+ . withComment ( node . description as any as string )
328
337
. withBlock (
329
338
node . values
330
339
. map ( enumOption => {
331
340
const optionName = this . convertName ( enumOption , { useTypesPrefix : false , transformUnderscore : true } ) ;
332
- const comment = transformComment ( ( enumOption . description as any ) as string , 1 ) ;
333
- const name = ( enumOption . name as unknown ) as string ;
341
+ const comment = transformComment ( enumOption . description as any as string , 1 ) ;
342
+ const name = enumOption . name as unknown as string ;
334
343
const enumValue : string | number = getValueFromConfig ( name ) ?? name ;
335
344
336
345
return comment + indent ( `${ optionName } : ${ wrapWithSingleQuotes ( enumValue ) } ` ) ;
@@ -345,7 +354,7 @@ export class TsVisitor<
345
354
. export ( )
346
355
. asKind ( this . config . constEnums ? 'const enum' : 'enum' )
347
356
. withName ( enumTypeName )
348
- . withComment ( ( node . description as any ) as string )
357
+ . withComment ( node . description as any as string )
349
358
. withBlock ( this . buildEnumValuesBlock ( enumName , node . values ) ) . string ;
350
359
}
351
360
0 commit comments