Skip to content

isTypeOfExpression is broken #20875

Closed
Closed
@tehwalris

Description

@tehwalris

TypeScript Version: 2.6.2
Code

import * as ts from 'typescript'

const testTypeOf = ts.createTypeOf(ts.createLiteral(""))
const testAwait = ts.createAwait(ts.createLiteral(""))

console.log(testTypeOf.kind, testAwait.kind) // 189, 191

console.log(ts.isTypeOfExpression(testTypeOf)) // Prints false, should be true
console.log(ts.isTypeOfExpression(testAwait)) // Prints true, should be false

Expected behavior:
ts.isTypeofExpression should return true (only) for TypeOfExpression nodes.

Actual behavior:
It returns true for AwaitExpression nodes instead.

Reason
The nodes both get created correctly (TypeOfExpression has kind 189 like it should), but the generated code for isTypeOfExpression uses the wrong number for kind: (from tsc.ts, starting on line 9132)

    function isTypeOfExpression(node) {
        return node.kind === 191;
    }
    ts.isTypeOfExpression = isTypeOfExpression;
    function isVoidExpression(node) {
        return node.kind === 190;
    }
    ts.isVoidExpression = isVoidExpression;
    function isAwaitExpression(node) {
        return node.kind === 191;
    }
    ts.isAwaitExpression = isAwaitExpression;

Note that some code uses the correct kind:

    function createTypeOf(expression) {
        var node = createSynthesizedNode(189);
        node.expression = ts.parenthesizePrefixOperand(expression);
        return node;
    }

Note that this issue also exists on master, even though the numbers for SyntaxKind enum values have changed.

I couldn't find where this code gets generated, so I haven't been able to investigate further.

Metadata

Metadata

Assignees

No one assigned

    Labels

    APIRelates to the public API for TypeScriptBugA bug in TypeScriptFixedA PR has been merged for this issueGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions