Skip to content

v0.52.0 Unique Names causes generation to fail when using generics #454

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Mobius5150 opened this issue Dec 28, 2021 · 1 comment
Open

Comments

@Mobius5150
Copy link

With the 0.5x versions of this package, the following will fail to compile with the --uniqueNames option:

export interface IBulkOperationEntity<EntityIdentifier, BulkOptions extends object = undefined> {
	entity: EntityIdentifier;
	opts?: BulkOptions;
}

export interface IBulkOperation<EntityIdentifier, BulkOptions extends object> {
	options: BulkOptions;
	entities: IBulkOperationEntity<EntityIdentifier>[];
}

export interface UserBulkBetaInvite extends IBulkOperation<string, {}> {
}

Run typescript-json-schema "src/test.ts" UserBulkBetaInvite --uniqueNames and you receive the following:

PS D:\tsj-repro> npx typescript-json-schema "src/test.ts" UserBulkBetaInvite --uniqueNames
(node:6884) UnhandledPromiseRejectionWarning: Error: Symbol "__type" has no valueDeclaration and 0 declarations.
    at getCanonicalDeclaration (D:\tsj-repro\node_modules\typescript-json-schema\dist\typescript-json-schema.js:258:11)
    at getSourceFile (D:\tsj-repro\node_modules\typescript-json-schema\dist\typescript-json-schema.js:261:23)
    at JsonSchemaGenerator.getTypeDefinition (D:\tsj-repro\node_modules\typescript-json-schema\dist\typescript-json-schema.js:931:34)
    at JsonSchemaGenerator.getDefinitionForProperty (D:\tsj-repro\node_modules\typescript-json-schema\dist\typescript-json-schema.js:510:31)
    at D:\tsj-repro\node_modules\typescript-json-schema\dist\typescript-json-schema.js:805:37
    at Array.reduce (<anonymous>)
    at JsonSchemaGenerator.getClassDefinition (D:\tsj-repro\node_modules\typescript-json-schema\dist\typescript-json-schema.js:803:45)
    at JsonSchemaGenerator.getTypeDefinition (D:\tsj-repro\node_modules\typescript-json-schema\dist\typescript-json-schema.js:1025:26)
    at JsonSchemaGenerator.getSchemaForSymbol (D:\tsj-repro\node_modules\typescript-json-schema\dist\typescript-json-schema.js:1056:24)
    at generateSchema (D:\tsj-repro\node_modules\typescript-json-schema\dist\typescript-json-schema.js:1236:30)
(node:6884) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:6884) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

However, if you leave off --uniqueNames then you get the following invalid output:

PS D:\tsj-repro> npx typescript-json-schema "src/test.ts" UserBulkBetaInvite  
{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "definitions": {
            "properties": {
                "entity": {
                    "type": "string"
                },
                "opts": {
                    "type": "undefined"
                }
            },
            "type": "object"
        }
    },
    "properties": {
        "entities": {
            "items": {
                "$ref": "#/definitions/IBulkOperationEntity<string,undefined>"
            },
            "type": "array"
        },
        "options": {
            "properties": {},
            "type": "object"
        }
    },
    "type": "object"
}
@cdaringe
Copy link

Seems like the AST parser may be making incorrect assumptions about the node on visit. Saw similar failure for a different type in our project as well.

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

Successfully merging a pull request may close this issue.

2 participants