ts-json-schema-generator icon indicating copy to clipboard operation
ts-json-schema-generator copied to clipboard

Generation failing for custom utility type

Open countnazgul opened this issue 1 year ago • 1 comments

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

countnazgul avatar Jan 23 '24 03:01 countnazgul

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.

ELigoP avatar Jan 31 '24 18:01 ELigoP