mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-13 02:45:24 -05:00
Fix(50161): Instantiation expressions trigger incorrect error messages (#52373)
This commit is contained in:
@@ -44708,7 +44708,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
return node.parent.kind === SyntaxKind.TypeReference;
|
||||
}
|
||||
|
||||
function isHeritageClauseElementIdentifier(node: Node): boolean {
|
||||
function isInNameOfExpressionWithTypeArguments(node: Node): boolean {
|
||||
while (node.parent.kind === SyntaxKind.PropertyAccessExpression) {
|
||||
node = node.parent;
|
||||
}
|
||||
@@ -44834,11 +44834,12 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
|
||||
name = name.parent as QualifiedName | PropertyAccessEntityNameExpression | JSDocMemberName;
|
||||
}
|
||||
|
||||
if (isHeritageClauseElementIdentifier(name)) {
|
||||
if (isInNameOfExpressionWithTypeArguments(name)) {
|
||||
let meaning = SymbolFlags.None;
|
||||
// In an interface or class, we're definitely interested in a type.
|
||||
if (name.parent.kind === SyntaxKind.ExpressionWithTypeArguments) {
|
||||
meaning = SymbolFlags.Type;
|
||||
// An 'ExpressionWithTypeArguments' may appear in type space (interface Foo extends Bar<T>),
|
||||
// value space (return foo<T>), or both(class Foo extends Bar<T>); ensure the meaning matches.
|
||||
meaning = isPartOfTypeNode(name) ? SymbolFlags.Type : SymbolFlags.Value;
|
||||
|
||||
// In a class 'extends' clause we are also looking for a value.
|
||||
if (isExpressionWithTypeArgumentsInClassExtendsClause(name.parent)) {
|
||||
|
||||
@@ -190,3 +190,4 @@ import "./unittests/tsserver/typingsInstaller";
|
||||
import "./unittests/tsserver/versionCache";
|
||||
import "./unittests/tsserver/watchEnvironment";
|
||||
import "./unittests/debugDeprecation";
|
||||
import "./unittests/tsserver/inconsistentErrorInEditor";
|
||||
@@ -0,0 +1,41 @@
|
||||
import * as ts from "../../_namespaces/ts";
|
||||
import {
|
||||
createServerHost,
|
||||
} from "../virtualFileSystemWithWatch";
|
||||
import {
|
||||
baselineTsserverLogs,
|
||||
createLoggerWithInMemoryLogs,
|
||||
createSession,
|
||||
verifyGetErrRequest,
|
||||
} from "./helpers";
|
||||
describe("unittests:: tsserver:: inconsistentErrorInEditor", () => {
|
||||
it("should not error", () => {
|
||||
const host = createServerHost([]);
|
||||
const session = createSession(host, { canUseEvents: true, noGetErrOnBackgroundUpdate: true, logger: createLoggerWithInMemoryLogs(host) });
|
||||
session.executeCommandSeq<ts.server.protocol.UpdateOpenRequest>({
|
||||
command: ts.server.protocol.CommandTypes.UpdateOpen,
|
||||
arguments: {
|
||||
changedFiles: [],
|
||||
closedFiles: [],
|
||||
openFiles: [
|
||||
{
|
||||
file: "^/untitled/ts-nul-authority/Untitled-1",
|
||||
fileContent: "export function foo<U>() {\r\n /*$*/return bar<U>;\r\n}\r\n\r\nexport function bar<T>(x: T) {\r\n return x;\r\n}\r\n\r\nlet x = foo()(42);",
|
||||
scriptKindName: "TS"
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
session.executeCommandSeq<ts.server.protocol.EncodedSemanticClassificationsRequest>({
|
||||
command: ts.server.protocol.CommandTypes.EncodedSemanticClassificationsFull,
|
||||
arguments: {
|
||||
file: "^/untitled/ts-nul-authority/Untitled-1",
|
||||
start: 0,
|
||||
length: 128,
|
||||
format: "2020"
|
||||
}
|
||||
});
|
||||
verifyGetErrRequest({ session, host, files: ["^/untitled/ts-nul-authority/Untitled-1"] });
|
||||
baselineTsserverLogs("inconsistentErrorInEditor", "should not error", session);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user