Skip to content

Mapped types with generic indexing failing. #301

Open
@avatarneil

Description

@avatarneil

The below code throws an error when attempting to generate a schema for type Thing. This is valid Typescript, and the compiler parses it with no issues.

Sample Code:
source.ts:

export const FOO_MAP = {
  foo: { bar: "bar", biz: "biz" },
  ex: { potato: "potato" }
};

defs.d.ts:

import { FOO_MAP } from "./source";

interface Thing {
  foos: { [S in keyof typeof FOO_MAP]: (keyof typeof FOO_MAP[S])[] | [] };
}

Console Command: typescript-json-schema "defs.d.ts" Thing
Error:

/Users/neilgoldader/.config/yarn/global/node_modules/typescript-json-schema/dist/typescript-json-schema.js:244
            var fixedTypes = elemTypes.map(function (elType) { return _this.getTypeDefinition(elType); });
                                       ^

TypeError: Cannot read property 'map' of undefined
    at JsonSchemaGenerator.getDefinitionForRootType (/Users/neilgoldader/.config/yarn/global/node_modules/typescript-json-schema/dist/typescript-json-schema.js:244:40)
    at JsonSchemaGenerator.getTypeDefinition (/Users/neilgoldader/.config/yarn/global/node_modules/typescript-json-schema/dist/typescript-json-schema.js:766:26)
    at JsonSchemaGenerator.getUnionDefinition (/Users/neilgoldader/.config/yarn/global/node_modules/typescript-json-schema/dist/typescript-json-schema.js:457:32)
    at JsonSchemaGenerator.getTypeDefinition (/Users/neilgoldader/.config/yarn/global/node_modules/typescript-json-schema/dist/typescript-json-schema.js:737:26)
    at JsonSchemaGenerator.getDefinitionForProperty (/Users/neilgoldader/.config/yarn/global/node_modules/typescript-json-schema/dist/typescript-json-schema.js:340:31)
    at /Users/neilgoldader/.config/yarn/global/node_modules/typescript-json-schema/dist/typescript-json-schema.js:614:37
    at Array.reduce (<anonymous>)
    at JsonSchemaGenerator.getClassDefinition (/Users/neilgoldader/.config/yarn/global/node_modules/typescript-json-schema/dist/typescript-json-schema.js:612:45)
    at JsonSchemaGenerator.getTypeDefinition (/Users/neilgoldader/.config/yarn/global/node_modules/typescript-json-schema/dist/typescript-json-schema.js:776:26)
    at JsonSchemaGenerator.getDefinitionForProperty (/Users/neilgoldader/.config/yarn/global/node_modules/typescript-json-schema/dist/typescript-json-schema.js:340:31)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions