ts-json-schema-generator
ts-json-schema-generator copied to clipboard
Generation failing for custom utility type
For some reason generation is failing for the following:
type AtLeastOne<T, U = { [K in keyof T]: Pick<T, K> }> = Partial<T> &
U[keyof U];
interface SomeInterface {
props: AtLeastOne<{
prop1: string[];
prop2: string[];
prop3: string[];
}>;
}
with the following error:
Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'getId')
at <anonymous> (C:\Dev\Temp\node_modules\ts-json-schema-generator\dist\src\Utils\nodeKey.js:43:57)
at getKey (C:\Dev\Temp\node_modules\ts-json-schema-generator\dist\src\Utils\nodeKey.js:43:40)
at getCacheKey (C:\Dev\Temp\node_modules\ts-json-schema-generator\dist\src\NodeParser.js:30:55)
at createType (C:\Dev\Temp\node_modules\ts-json-schema-generator\dist\src\ChainNodeParser.js:25:41)
Have a look at the codesandbox example and ts playground
I've got similar issue when using kind of A<T, U = something depending on T> and then referencing this as A<SomeType>. I hoped U will be inferred, but got this error instead. Had to go another way.