mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-18 13:59:04 -05:00
fix(49223): checker.getTypeAtLocation for ExpressionWithTypeArguments returns an error any type (#49284)
* fix(49223): handle ExpressionWithTypeArguments nodes in isExpressionNode * Update src/compiler/utilities.ts * Just use `!isHeritageClause(node.parent)`. Co-authored-by: Daniel Rosenwasser <DanielRosenwasser@users.noreply.github.com>
This commit is contained in:
@@ -2016,6 +2016,8 @@ namespace ts {
|
||||
case SyntaxKind.AwaitExpression:
|
||||
case SyntaxKind.MetaProperty:
|
||||
return true;
|
||||
case SyntaxKind.ExpressionWithTypeArguments:
|
||||
return !isHeritageClause(node.parent);
|
||||
case SyntaxKind.QualifiedName:
|
||||
while (node.parent.kind === SyntaxKind.QualifiedName) {
|
||||
node = node.parent;
|
||||
|
||||
@@ -131,6 +131,30 @@ describe("unittests:: Public APIs:: getTypeAtLocation", () => {
|
||||
assert.equal(type.flags, ts.TypeFlags.Any);
|
||||
});
|
||||
|
||||
it("works on ExpressionWithTypeArguments", () => {
|
||||
const content = `
|
||||
function fn<T>(value: T) {
|
||||
return { value };
|
||||
}
|
||||
const foo = fn<string>;
|
||||
`;
|
||||
const host = new fakes.CompilerHost(vfs.createFromFileSystem(
|
||||
Harness.IO,
|
||||
/*ignoreCase*/ true,
|
||||
{ documents: [new documents.TextDocument("/file.ts", content)], cwd: "/" }));
|
||||
|
||||
const program = ts.createProgram({
|
||||
host,
|
||||
rootNames: ["/file.ts"],
|
||||
options: { noLib: true }
|
||||
});
|
||||
|
||||
const checker = program.getTypeChecker();
|
||||
const file = program.getSourceFile("/file.ts")!;
|
||||
const [declaration] = (ts.findLast(file.statements, ts.isVariableStatement) as ts.VariableStatement).declarationList.declarations;
|
||||
assert.equal(checker.getTypeAtLocation(declaration.initializer!).flags, ts.TypeFlags.Object);
|
||||
});
|
||||
|
||||
it("returns an errorType for VariableDeclaration with BindingPattern name", () => {
|
||||
const content = "const foo = [1];\n" + "const [a] = foo;";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user