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

Already on GitHub? Sign in to your account

Unhandled node kind: TypePredicate #94

Open
mati-o opened this issue Nov 8, 2021 · 0 comments
Open

Unhandled node kind: TypePredicate #94

mati-o opened this issue Nov 8, 2021 · 0 comments

Comments

@mati-o
Copy link

mati-o commented Nov 8, 2021

Whenever a type predicate is used, as in the following example:

function foo(value: any): value is string {
    return true;
}

The factory code generator does not handle the type predicate node correctly:

Expected

  factory.createFunctionDeclaration(
    undefined,
    undefined,
    undefined,
    factory.createIdentifier("foo"),
    undefined,
    [factory.createParameterDeclaration(
      undefined,
      undefined,
      undefined,
      factory.createIdentifier("value"),
      undefined,
      factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),
      undefined
    )],
    factory.createTypePredicateNode(undefined, factory.createIdentifier("value"), factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)),
    factory.createBlock(
      [factory.createReturnStatement(factory.createTrue())],
      true
    )
  )

Actual

  factory.createFunctionDeclaration(
    undefined,
    undefined,
    undefined,
    factory.createIdentifier("foo"),
    undefined,
    [factory.createParameterDeclaration(
      undefined,
      undefined,
      undefined,
      factory.createIdentifier("value"),
      undefined,
      factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword),
      undefined
    )],
    /* Unhandled node kind: TypePredicate */,
    factory.createBlock(
      [factory.createReturnStatement(factory.createTrue())],
      true
    )
  )

Diff in summary (red is current behavior, green is desired):

-    /* Unhandled node kind: TypePredicate */,
+    factory.createTypePredicateNode(undefined, factory.createIdentifier("value"), factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword)),
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