Skip to content

Generics like Row<T> { value: T } don't work with createAssertType, although many other ones work perfectly #59

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
dko-slapdash opened this issue Apr 20, 2020 · 2 comments

Comments

@dko-slapdash
Copy link
Contributor

I noticed that some generics don't work when fed to createAssertType(), although many other generics work perfectly. E.g. an example of what doesn't work:

type Row<T> = {
  value: T;
};

createAssertType<Row<number>>();

// Throws the error:

    NestedError: Failed to transform node at: ....ts:96:3
      at transformNodeAndChildren (../../node_modules/typescript-is/src/transform-inline/transformer.ts:37:15)
      at ../../node_modules/typescript-is/src/transform-inline/transformer.ts:39:62
      at visitNode (../../node_modules/typescript/lib/typescript.js:74115:23)
      at Object.visitEachChild (../../node_modules/typescript/lib/typescript.js:74398:59)
      at transformNodeAndChildren (../../node_modules/typescript-is/src/transform-inline/transformer.ts:39:15)
      at ../../node_modules/typescript-is/src/transform-inline/transformer.ts:39:62
      at visitNodes (../../node_modules/typescript/lib/typescript.js:74166:48)
      at visitLexicalEnvironment (../../node_modules/typescript/lib/typescript.js:74199:22)
      at Object.visitEachChild (../../node_modules/typescript/lib/typescript.js:74514:54)
      at transformNodeAndChildren (../../node_modules/typescript-is/src/transform-inline/transformer.ts:39:15)
      Caused By: Error: Unbound type parameter, missing type node.
      at visitTypeParameter (../../node_modules/typescript-is/src/transform-inline/visitor-type-check.ts:375:15)
      at visitType (../../node_modules/typescript-is/src/transform-inline/visitor-type-check.ts:627:16)
      at ../../node_modules/typescript-is/src/transform-inline/visitor-type-check.ts:254:27
          at Array.map (<anonymous>)
      at ../../node_modules/typescript-is/src/transform-inline/visitor-type-check.ts:248:34
      at Object.setFunctionIfNotExists (../../node_modules/typescript-is/src/transform-inline/visitor-utils.ts:40:46)
      at visitRegularObjectType (../../node_modules/typescript-is/src/transform-inline/visitor-type-check.ts:209:25)
      at visitObjectType (../../node_modules/typescript-is/src/transform-inline/visitor-type-check.ts:400:16)
      at Object.visitType (../../node_modules/typescript-is/src/transform-inline/visitor-type-check.ts:630:16)
      at createArrowFunction (../../node_modules/typescript-is/src/transform-inline/transform-node.ts:16:15)

And here is a WORKING example:

type Rec<K extends keyof any, T> = {
  [P in K]: T;
};

createAssertType<Rec<string, number>>();
@woutervh-
Copy link
Owner

hi @dko-slapdash

type Row<T> = {
  value: T;
};

createAssertType<Row<number>>();

Should work perfectly fine. This is most likely a bug. I will investigate it.

@woutervh-
Copy link
Owner

Hi @dko-slapdash

I've released v0.17.0 which hopefully fixes the issue for you:
https://github.com/woutervh-/typescript-is/releases/tag/v0.17.0

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

2 participants