Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function with generic keyof param crashes #1761

Open
LeviticusMB opened this issue Aug 30, 2023 · 1 comment
Open

Function with generic keyof param crashes #1761

LeviticusMB opened this issue Aug 30, 2023 · 1 comment

Comments

@LeviticusMB
Copy link

I'm upgrading from 0.97.0 to 1.3.0 and now ts-json-schema-generator crashes. I have a schema.ts with exported types plus a helper function for validating the types using the generated schema.

馃榾 mb@bia:test$ npx ts-json-schema-generator --path schema.ts 
/Users/mb/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/ts-json-schema-generator.js:95
        throw error;
        ^

TypeError: Cannot read properties of undefined (reading 'getId')
    at /Users/mb/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/src/NodeParser/IndexedAccessTypeNodeParser.js:54:76
    at Array.map (<anonymous>)
    at IndexedAccessTypeNodeParser.createType (/Users/mb/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/src/NodeParser/IndexedAccessTypeNodeParser.js:52:42)
    at ChainNodeParser.createType (/Users/mb/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/src/ChainNodeParser.js:28:54)
    at ParameterParser.createType (/Users/mb/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/src/NodeParser/ParameterParser.js:16:37)
    at AnnotatedNodeParser.createType (/Users/mb/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/src/NodeParser/AnnotatedNodeParser.js:30:47)
    at ChainNodeParser.createType (/Users/mb/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/src/ChainNodeParser.js:28:54)
    at /Users/mb/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/src/NodeParser/FunctionParser.js:24:41
    at Array.map (<anonymous>)
    at FunctionParser.createType (/Users/mb/.npm/_npx/dec19a6f9609cbed/node_modules/ts-json-schema-generator/dist/src/NodeParser/FunctionParser.js:23:48)
馃懣 mb@bia:test$ 

schema.ts contains:

export interface A {
    aProp: string;
}

export interface B {
    bProp: number;
}

interface Objects {
    'A': A,
    'B': B,
}

export function validate<K extends keyof Objects>(type: K, object: Objects[K]): Objects[K] {
    // Actual validation using generated schema and AJV here
    return object;
}

It looks like it broke in between 1.0.0 and 1.1.0.

@LeviticusMB
Copy link
Author

BTW a workaround for my issue would be to add /** @hidden */ to validate() (#330), but still ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant