Skip to content

Unexpected key type "unknown" for this node. (expected "UnionType" or "StringType") when using PickDeep from type-fest #2312

@crycode-de

Description

@crycode-de

Hi,

I'm trying to migrate from typescript-json-schema to ts-json-schema-generator but I'm stuck with an error:

Error: Unexpected key type "unknown" for this node. (expected "UnionType" or "StringType")

Figured out it's related to the PickDeep type from type-fest which I'm using in my project.

See example and full error below.

Any ideas how to solve this issue?

Simple example to reproduce the issue

Install dependencies:

npm install ts-json-schema-generator type-fest typescript

Create a example.ts file:

import type { PickDeep } from 'type-fest';

export interface SomeTest {
  a: string;
  b: string;
  c: {
    c1: string;
    c2: string;
  };
};

export type SomePicked = PickDeep<SomeTest, 'a' | 'c.c1'>;

Try to create the schema:

./node_modules/.bin/ts-json-schema-generator --path example.ts --type 'SomePicked'
/tmp/tmp.tEprWf2fAX/node_modules/type-fest/source/internal/object.d.ts:36:6 - error TSJ - 105: Unexpected key type "unknown" for this node. (expected "UnionType" or "StringType")

36    : {[_ in Key]: Value};
        ~~~~~~~~~~~~~~~~~~~

Error: Unexpected key type "unknown" for this node. (expected "UnionType" or "StringType")
    at MappedTypeNodeParser.createType (/tmp/tmp.tEprWf2fAX/node_modules/ts-json-schema-generator/dist/src/NodeParser/MappedTypeNodeParser.js:76:15)
    at ChainNodeParser.createType (/tmp/tmp.tEprWf2fAX/node_modules/ts-json-schema-generator/dist/src/ChainNodeParser.js:31:49)
    at ConditionalTypeNodeParser.createType (/tmp/tmp.tEprWf2fAX/node_modules/ts-json-schema-generator/dist/src/NodeParser/ConditionalTypeNodeParser.js:48:49)
    at ChainNodeParser.createType (/tmp/tmp.tEprWf2fAX/node_modules/ts-json-schema-generator/dist/src/ChainNodeParser.js:31:49)
    at ConditionalTypeNodeParser.createType (/tmp/tmp.tEprWf2fAX/node_modules/ts-json-schema-generator/dist/src/NodeParser/ConditionalTypeNodeParser.js:48:49)
    at ChainNodeParser.createType (/tmp/tmp.tEprWf2fAX/node_modules/ts-json-schema-generator/dist/src/ChainNodeParser.js:31:49)
    at TypeAliasNodeParser.createType (/tmp/tmp.tEprWf2fAX/node_modules/ts-json-schema-generator/dist/src/NodeParser/TypeAliasNodeParser.js:36:43)
    at AnnotatedNodeParser.createType (/tmp/tmp.tEprWf2fAX/node_modules/ts-json-schema-generator/dist/src/NodeParser/AnnotatedNodeParser.js:29:47)
    at ExposeNodeParser.createType (/tmp/tmp.tEprWf2fAX/node_modules/ts-json-schema-generator/dist/src/ExposeNodeParser.js:24:45)
    at CircularReferenceNodeParser.createType (/tmp/tmp.tEprWf2fAX/node_modules/ts-json-schema-generator/dist/src/CircularReferenceNodeParser.js:22:43)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions