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:
Oleksandr T
2022-06-02 17:28:36 -07:00
committed by GitHub
co-authored by Daniel Rosenwasser
parent 34fe835f33
commit 9c8e6b53b8
8 changed files with 80 additions and 0 deletions
+24
View File
@@ -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;";