ts-json-schema-generator
ts-json-schema-generator copied to clipboard
Unknown node of kind "NewExpression" - When using Set values as union
This might be a fringe case and I'm going to workaround it using Enums instead but I still think this is intersting and should probably be fixed / we should add a proper error here.
When using a normal union type like so 'a' | 'b' the schema generator works just fine.
But when creating a union type from a Set (it's the same union) we an error.
to create the union first create a helper type like so:
export type SetValues<T> = T extends Set<infer V> ? V : never;
Then call this type with your set (it is important to use as const with the provided array)
type myUnion = SetValues<new Set(['a', 'b'] as const)> // 'a' | 'b'
use this type in an interface to generate a schema
Get following error:
UnknownNodeError: Unknown node of kind "NewExpression" at ChainNodeParser.getNodeParser (C:\project\node_modules\ts-json-schema-generator\src\ChainNodeParser.ts:50:15)