From c0bbb9b40e799ff62d087f7159b0bef50e2e4cf4 Mon Sep 17 00:00:00 2001 From: Daniel Rosenwasser Date: Wed, 15 May 2019 12:00:17 -0700 Subject: [PATCH] Update LKG. --- lib/tsc.js | 32 +++++++++++++++++------ lib/tsserver.js | 54 ++++++++++++++++++++++++++++----------- lib/tsserverlibrary.js | 54 ++++++++++++++++++++++++++++----------- lib/typescript.js | 54 ++++++++++++++++++++++++++++----------- lib/typescriptServices.js | 54 ++++++++++++++++++++++++++++----------- lib/typingsInstaller.js | 35 ++++++++++++++++++------- 6 files changed, 206 insertions(+), 77 deletions(-) diff --git a/lib/tsc.js b/lib/tsc.js index 9c85a281f897b..b9ede744acb65 100644 --- a/lib/tsc.js +++ b/lib/tsc.js @@ -33758,8 +33758,7 @@ var ts; function getSimplifiedType(type, writing) { return type.flags & 8388608 ? getSimplifiedIndexedAccessType(type, writing) : type.flags & 16777216 ? getSimplifiedConditionalType(type, writing) : - type.flags & 33554432 ? writing ? type.typeVariable : type.substitute : - type; + type; } function distributeIndexOverObjectType(objectType, indexType, writing) { if (objectType.flags & 3145728) { @@ -35512,7 +35511,7 @@ var ts; var depth = 0; var expandingFlags = 0; var overflow = false; - var suppressNextError = false; + var overrideNextErrorInfo; ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking"); var result = isRelatedTo(source, target, !!errorNode, headMessage); if (overflow) { @@ -35618,10 +35617,16 @@ var ts; if (isFreshLiteralType(target)) { target = target.regularType; } - if (source.flags & 58720256) { + if (source.flags & 33554432) { + source = source.substitute; + } + if (target.flags & 33554432) { + target = target.typeVariable; + } + if (source.flags & 25165824) { source = getSimplifiedType(source, false); } - if (target.flags & 58720256) { + if (target.flags & 25165824) { target = getSimplifiedType(target, true); } if (target.flags & 1048576 && source.flags & 524288 && @@ -35713,10 +35718,14 @@ var ts; } } if (!result && reportErrors) { - var maybeSuppress = suppressNextError; - suppressNextError = false; + var maybeSuppress = overrideNextErrorInfo; + overrideNextErrorInfo = undefined; if (source.flags & 524288 && target.flags & 524288) { + var currentError = errorInfo; tryElaborateArrayLikeErrors(source, target, reportErrors); + if (errorInfo !== currentError) { + maybeSuppress = errorInfo; + } } if (source.flags & 524288 && target.flags & 131068) { tryElaborateErrorsForPrimitivesAndObjects(source, target); @@ -36501,9 +36510,10 @@ var ts; if (unmatchedProperty) { if (reportErrors) { var props = ts.arrayFrom(getUnmatchedProperties(source, target, requireOptionalProperties, false)); + var shouldSkipElaboration = false; if (!headMessage || (headMessage.code !== ts.Diagnostics.Class_0_incorrectly_implements_interface_1.code && headMessage.code !== ts.Diagnostics.Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass.code)) { - suppressNextError = true; + shouldSkipElaboration = true; } if (props.length === 1) { var propName = symbolToString(unmatchedProperty); @@ -36511,6 +36521,9 @@ var ts; if (ts.length(unmatchedProperty.declarations)) { associateRelatedInfo(ts.createDiagnosticForNode(unmatchedProperty.declarations[0], ts.Diagnostics._0_is_declared_here, propName)); } + if (shouldSkipElaboration) { + overrideNextErrorInfo = errorInfo; + } } else if (tryElaborateArrayLikeErrors(source, target, false)) { if (props.length > 5) { @@ -36519,6 +36532,9 @@ var ts; else { reportError(ts.Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2, typeToString(source), typeToString(target), ts.map(props, function (p) { return symbolToString(p); }).join(", ")); } + if (shouldSkipElaboration) { + overrideNextErrorInfo = errorInfo; + } } } return 0; diff --git a/lib/tsserver.js b/lib/tsserver.js index 21f3efd034f9b..8d3f91a6a558b 100644 --- a/lib/tsserver.js +++ b/lib/tsserver.js @@ -3500,7 +3500,7 @@ var ts; /* @internal */ TypeFlags[TypeFlags["ObjectFlagsType"] = 3899392] = "ObjectFlagsType"; /* @internal */ - TypeFlags[TypeFlags["Simplifiable"] = 58720256] = "Simplifiable"; + TypeFlags[TypeFlags["Simplifiable"] = 25165824] = "Simplifiable"; // 'Narrowable' types are types where narrowing actually narrows. // This *should* be every type other than null, undefined, void, and never TypeFlags[TypeFlags["Narrowable"] = 133970943] = "Narrowable"; @@ -40634,8 +40634,7 @@ var ts; function getSimplifiedType(type, writing) { return type.flags & 8388608 /* IndexedAccess */ ? getSimplifiedIndexedAccessType(type, writing) : type.flags & 16777216 /* Conditional */ ? getSimplifiedConditionalType(type, writing) : - type.flags & 33554432 /* Substitution */ ? writing ? type.typeVariable : type.substitute : - type; + type; } function distributeIndexOverObjectType(objectType, indexType, writing) { // (T | U)[K] -> T[K] | U[K] (reading) @@ -42612,7 +42611,7 @@ var ts; var depth = 0; var expandingFlags = 0 /* None */; var overflow = false; - var suppressNextError = false; + var overrideNextErrorInfo; ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking"); var result = isRelatedTo(source, target, /*reportErrors*/ !!errorNode, headMessage); if (overflow) { @@ -42736,10 +42735,16 @@ var ts; if (isFreshLiteralType(target)) { target = target.regularType; } - if (source.flags & 58720256 /* Simplifiable */) { + if (source.flags & 33554432 /* Substitution */) { + source = source.substitute; + } + if (target.flags & 33554432 /* Substitution */) { + target = target.typeVariable; + } + if (source.flags & 25165824 /* Simplifiable */) { source = getSimplifiedType(source, /*writing*/ false); } - if (target.flags & 58720256 /* Simplifiable */) { + if (target.flags & 25165824 /* Simplifiable */) { target = getSimplifiedType(target, /*writing*/ true); } // Try to see if we're relating something like `Foo` -> `Bar | null | undefined`. @@ -42868,10 +42873,14 @@ var ts; } } if (!result && reportErrors) { - var maybeSuppress = suppressNextError; - suppressNextError = false; + var maybeSuppress = overrideNextErrorInfo; + overrideNextErrorInfo = undefined; if (source.flags & 524288 /* Object */ && target.flags & 524288 /* Object */) { + var currentError = errorInfo; tryElaborateArrayLikeErrors(source, target, reportErrors); + if (errorInfo !== currentError) { + maybeSuppress = errorInfo; + } } if (source.flags & 524288 /* Object */ && target.flags & 131068 /* Primitive */) { tryElaborateErrorsForPrimitivesAndObjects(source, target); @@ -43793,9 +43802,10 @@ var ts; if (unmatchedProperty) { if (reportErrors) { var props = ts.arrayFrom(getUnmatchedProperties(source, target, requireOptionalProperties, /*matchDiscriminantProperties*/ false)); + var shouldSkipElaboration = false; if (!headMessage || (headMessage.code !== ts.Diagnostics.Class_0_incorrectly_implements_interface_1.code && headMessage.code !== ts.Diagnostics.Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass.code)) { - suppressNextError = true; // Retain top-level error for interface implementing issues, otherwise omit it + shouldSkipElaboration = true; // Retain top-level error for interface implementing issues, otherwise omit it } if (props.length === 1) { var propName = symbolToString(unmatchedProperty); @@ -43803,6 +43813,9 @@ var ts; if (ts.length(unmatchedProperty.declarations)) { associateRelatedInfo(ts.createDiagnosticForNode(unmatchedProperty.declarations[0], ts.Diagnostics._0_is_declared_here, propName)); } + if (shouldSkipElaboration) { + overrideNextErrorInfo = errorInfo; + } } else if (tryElaborateArrayLikeErrors(source, target, /*reportErrors*/ false)) { if (props.length > 5) { // arbitrary cutoff for too-long list form @@ -43811,7 +43824,11 @@ var ts; else { reportError(ts.Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2, typeToString(source), typeToString(target), ts.map(props, function (p) { return symbolToString(p); }).join(", ")); } + if (shouldSkipElaboration) { + overrideNextErrorInfo = errorInfo; + } } + // ELSE: No array like or unmatched property error - just issue top level error (errorInfo = undefined) } return 0 /* False */; } @@ -121633,30 +121650,37 @@ var ts; return undefined; } var typeChecker = program.getTypeChecker(); - var symbol = getSymbolAtLocationForQuickInfo(node, typeChecker); + var nodeForQuickInfo = getNodeForQuickInfo(node); + var symbol = getSymbolAtLocationForQuickInfo(nodeForQuickInfo, typeChecker); if (!symbol || typeChecker.isUnknownSymbol(symbol)) { - var type_2 = shouldGetType(sourceFile, node, position) ? typeChecker.getTypeAtLocation(node) : undefined; + var type_2 = shouldGetType(sourceFile, nodeForQuickInfo, position) ? typeChecker.getTypeAtLocation(nodeForQuickInfo) : undefined; return type_2 && { kind: "" /* unknown */, kindModifiers: "" /* none */, - textSpan: ts.createTextSpanFromNode(node, sourceFile), - displayParts: typeChecker.runWithCancellationToken(cancellationToken, function (typeChecker) { return ts.typeToDisplayParts(typeChecker, type_2, ts.getContainerNode(node)); }), + textSpan: ts.createTextSpanFromNode(nodeForQuickInfo, sourceFile), + displayParts: typeChecker.runWithCancellationToken(cancellationToken, function (typeChecker) { return ts.typeToDisplayParts(typeChecker, type_2, ts.getContainerNode(nodeForQuickInfo)); }), documentation: type_2.symbol ? type_2.symbol.getDocumentationComment(typeChecker) : undefined, tags: type_2.symbol ? type_2.symbol.getJsDocTags() : undefined }; } var _a = typeChecker.runWithCancellationToken(cancellationToken, function (typeChecker) { - return ts.SymbolDisplay.getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, ts.getContainerNode(node), node); + return ts.SymbolDisplay.getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, ts.getContainerNode(nodeForQuickInfo), nodeForQuickInfo); }), symbolKind = _a.symbolKind, displayParts = _a.displayParts, documentation = _a.documentation, tags = _a.tags; return { kind: symbolKind, kindModifiers: ts.SymbolDisplay.getSymbolModifiers(symbol), - textSpan: ts.createTextSpanFromNode(node, sourceFile), + textSpan: ts.createTextSpanFromNode(nodeForQuickInfo, sourceFile), displayParts: displayParts, documentation: documentation, tags: tags, }; } + function getNodeForQuickInfo(node) { + if (ts.isNewExpression(node.parent) && node.pos === node.parent.pos) { + return node.parent.expression; + } + return node; + } function shouldGetType(sourceFile, node, position) { switch (node.kind) { case 73 /* Identifier */: diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js index ba6d4a84160b2..e577c4ae9bef0 100644 --- a/lib/tsserverlibrary.js +++ b/lib/tsserverlibrary.js @@ -3499,7 +3499,7 @@ var ts; /* @internal */ TypeFlags[TypeFlags["ObjectFlagsType"] = 3899392] = "ObjectFlagsType"; /* @internal */ - TypeFlags[TypeFlags["Simplifiable"] = 58720256] = "Simplifiable"; + TypeFlags[TypeFlags["Simplifiable"] = 25165824] = "Simplifiable"; // 'Narrowable' types are types where narrowing actually narrows. // This *should* be every type other than null, undefined, void, and never TypeFlags[TypeFlags["Narrowable"] = 133970943] = "Narrowable"; @@ -40633,8 +40633,7 @@ var ts; function getSimplifiedType(type, writing) { return type.flags & 8388608 /* IndexedAccess */ ? getSimplifiedIndexedAccessType(type, writing) : type.flags & 16777216 /* Conditional */ ? getSimplifiedConditionalType(type, writing) : - type.flags & 33554432 /* Substitution */ ? writing ? type.typeVariable : type.substitute : - type; + type; } function distributeIndexOverObjectType(objectType, indexType, writing) { // (T | U)[K] -> T[K] | U[K] (reading) @@ -42611,7 +42610,7 @@ var ts; var depth = 0; var expandingFlags = 0 /* None */; var overflow = false; - var suppressNextError = false; + var overrideNextErrorInfo; ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking"); var result = isRelatedTo(source, target, /*reportErrors*/ !!errorNode, headMessage); if (overflow) { @@ -42735,10 +42734,16 @@ var ts; if (isFreshLiteralType(target)) { target = target.regularType; } - if (source.flags & 58720256 /* Simplifiable */) { + if (source.flags & 33554432 /* Substitution */) { + source = source.substitute; + } + if (target.flags & 33554432 /* Substitution */) { + target = target.typeVariable; + } + if (source.flags & 25165824 /* Simplifiable */) { source = getSimplifiedType(source, /*writing*/ false); } - if (target.flags & 58720256 /* Simplifiable */) { + if (target.flags & 25165824 /* Simplifiable */) { target = getSimplifiedType(target, /*writing*/ true); } // Try to see if we're relating something like `Foo` -> `Bar | null | undefined`. @@ -42867,10 +42872,14 @@ var ts; } } if (!result && reportErrors) { - var maybeSuppress = suppressNextError; - suppressNextError = false; + var maybeSuppress = overrideNextErrorInfo; + overrideNextErrorInfo = undefined; if (source.flags & 524288 /* Object */ && target.flags & 524288 /* Object */) { + var currentError = errorInfo; tryElaborateArrayLikeErrors(source, target, reportErrors); + if (errorInfo !== currentError) { + maybeSuppress = errorInfo; + } } if (source.flags & 524288 /* Object */ && target.flags & 131068 /* Primitive */) { tryElaborateErrorsForPrimitivesAndObjects(source, target); @@ -43792,9 +43801,10 @@ var ts; if (unmatchedProperty) { if (reportErrors) { var props = ts.arrayFrom(getUnmatchedProperties(source, target, requireOptionalProperties, /*matchDiscriminantProperties*/ false)); + var shouldSkipElaboration = false; if (!headMessage || (headMessage.code !== ts.Diagnostics.Class_0_incorrectly_implements_interface_1.code && headMessage.code !== ts.Diagnostics.Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass.code)) { - suppressNextError = true; // Retain top-level error for interface implementing issues, otherwise omit it + shouldSkipElaboration = true; // Retain top-level error for interface implementing issues, otherwise omit it } if (props.length === 1) { var propName = symbolToString(unmatchedProperty); @@ -43802,6 +43812,9 @@ var ts; if (ts.length(unmatchedProperty.declarations)) { associateRelatedInfo(ts.createDiagnosticForNode(unmatchedProperty.declarations[0], ts.Diagnostics._0_is_declared_here, propName)); } + if (shouldSkipElaboration) { + overrideNextErrorInfo = errorInfo; + } } else if (tryElaborateArrayLikeErrors(source, target, /*reportErrors*/ false)) { if (props.length > 5) { // arbitrary cutoff for too-long list form @@ -43810,7 +43823,11 @@ var ts; else { reportError(ts.Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2, typeToString(source), typeToString(target), ts.map(props, function (p) { return symbolToString(p); }).join(", ")); } + if (shouldSkipElaboration) { + overrideNextErrorInfo = errorInfo; + } } + // ELSE: No array like or unmatched property error - just issue top level error (errorInfo = undefined) } return 0 /* False */; } @@ -121976,30 +121993,37 @@ var ts; return undefined; } var typeChecker = program.getTypeChecker(); - var symbol = getSymbolAtLocationForQuickInfo(node, typeChecker); + var nodeForQuickInfo = getNodeForQuickInfo(node); + var symbol = getSymbolAtLocationForQuickInfo(nodeForQuickInfo, typeChecker); if (!symbol || typeChecker.isUnknownSymbol(symbol)) { - var type_2 = shouldGetType(sourceFile, node, position) ? typeChecker.getTypeAtLocation(node) : undefined; + var type_2 = shouldGetType(sourceFile, nodeForQuickInfo, position) ? typeChecker.getTypeAtLocation(nodeForQuickInfo) : undefined; return type_2 && { kind: "" /* unknown */, kindModifiers: "" /* none */, - textSpan: ts.createTextSpanFromNode(node, sourceFile), - displayParts: typeChecker.runWithCancellationToken(cancellationToken, function (typeChecker) { return ts.typeToDisplayParts(typeChecker, type_2, ts.getContainerNode(node)); }), + textSpan: ts.createTextSpanFromNode(nodeForQuickInfo, sourceFile), + displayParts: typeChecker.runWithCancellationToken(cancellationToken, function (typeChecker) { return ts.typeToDisplayParts(typeChecker, type_2, ts.getContainerNode(nodeForQuickInfo)); }), documentation: type_2.symbol ? type_2.symbol.getDocumentationComment(typeChecker) : undefined, tags: type_2.symbol ? type_2.symbol.getJsDocTags() : undefined }; } var _a = typeChecker.runWithCancellationToken(cancellationToken, function (typeChecker) { - return ts.SymbolDisplay.getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, ts.getContainerNode(node), node); + return ts.SymbolDisplay.getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, ts.getContainerNode(nodeForQuickInfo), nodeForQuickInfo); }), symbolKind = _a.symbolKind, displayParts = _a.displayParts, documentation = _a.documentation, tags = _a.tags; return { kind: symbolKind, kindModifiers: ts.SymbolDisplay.getSymbolModifiers(symbol), - textSpan: ts.createTextSpanFromNode(node, sourceFile), + textSpan: ts.createTextSpanFromNode(nodeForQuickInfo, sourceFile), displayParts: displayParts, documentation: documentation, tags: tags, }; } + function getNodeForQuickInfo(node) { + if (ts.isNewExpression(node.parent) && node.pos === node.parent.pos) { + return node.parent.expression; + } + return node; + } function shouldGetType(sourceFile, node, position) { switch (node.kind) { case 73 /* Identifier */: diff --git a/lib/typescript.js b/lib/typescript.js index ce4ed081dc6fe..f723a652839a5 100644 --- a/lib/typescript.js +++ b/lib/typescript.js @@ -3488,7 +3488,7 @@ var ts; /* @internal */ TypeFlags[TypeFlags["ObjectFlagsType"] = 3899392] = "ObjectFlagsType"; /* @internal */ - TypeFlags[TypeFlags["Simplifiable"] = 58720256] = "Simplifiable"; + TypeFlags[TypeFlags["Simplifiable"] = 25165824] = "Simplifiable"; // 'Narrowable' types are types where narrowing actually narrows. // This *should* be every type other than null, undefined, void, and never TypeFlags[TypeFlags["Narrowable"] = 133970943] = "Narrowable"; @@ -40622,8 +40622,7 @@ var ts; function getSimplifiedType(type, writing) { return type.flags & 8388608 /* IndexedAccess */ ? getSimplifiedIndexedAccessType(type, writing) : type.flags & 16777216 /* Conditional */ ? getSimplifiedConditionalType(type, writing) : - type.flags & 33554432 /* Substitution */ ? writing ? type.typeVariable : type.substitute : - type; + type; } function distributeIndexOverObjectType(objectType, indexType, writing) { // (T | U)[K] -> T[K] | U[K] (reading) @@ -42600,7 +42599,7 @@ var ts; var depth = 0; var expandingFlags = 0 /* None */; var overflow = false; - var suppressNextError = false; + var overrideNextErrorInfo; ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking"); var result = isRelatedTo(source, target, /*reportErrors*/ !!errorNode, headMessage); if (overflow) { @@ -42724,10 +42723,16 @@ var ts; if (isFreshLiteralType(target)) { target = target.regularType; } - if (source.flags & 58720256 /* Simplifiable */) { + if (source.flags & 33554432 /* Substitution */) { + source = source.substitute; + } + if (target.flags & 33554432 /* Substitution */) { + target = target.typeVariable; + } + if (source.flags & 25165824 /* Simplifiable */) { source = getSimplifiedType(source, /*writing*/ false); } - if (target.flags & 58720256 /* Simplifiable */) { + if (target.flags & 25165824 /* Simplifiable */) { target = getSimplifiedType(target, /*writing*/ true); } // Try to see if we're relating something like `Foo` -> `Bar | null | undefined`. @@ -42856,10 +42861,14 @@ var ts; } } if (!result && reportErrors) { - var maybeSuppress = suppressNextError; - suppressNextError = false; + var maybeSuppress = overrideNextErrorInfo; + overrideNextErrorInfo = undefined; if (source.flags & 524288 /* Object */ && target.flags & 524288 /* Object */) { + var currentError = errorInfo; tryElaborateArrayLikeErrors(source, target, reportErrors); + if (errorInfo !== currentError) { + maybeSuppress = errorInfo; + } } if (source.flags & 524288 /* Object */ && target.flags & 131068 /* Primitive */) { tryElaborateErrorsForPrimitivesAndObjects(source, target); @@ -43781,9 +43790,10 @@ var ts; if (unmatchedProperty) { if (reportErrors) { var props = ts.arrayFrom(getUnmatchedProperties(source, target, requireOptionalProperties, /*matchDiscriminantProperties*/ false)); + var shouldSkipElaboration = false; if (!headMessage || (headMessage.code !== ts.Diagnostics.Class_0_incorrectly_implements_interface_1.code && headMessage.code !== ts.Diagnostics.Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass.code)) { - suppressNextError = true; // Retain top-level error for interface implementing issues, otherwise omit it + shouldSkipElaboration = true; // Retain top-level error for interface implementing issues, otherwise omit it } if (props.length === 1) { var propName = symbolToString(unmatchedProperty); @@ -43791,6 +43801,9 @@ var ts; if (ts.length(unmatchedProperty.declarations)) { associateRelatedInfo(ts.createDiagnosticForNode(unmatchedProperty.declarations[0], ts.Diagnostics._0_is_declared_here, propName)); } + if (shouldSkipElaboration) { + overrideNextErrorInfo = errorInfo; + } } else if (tryElaborateArrayLikeErrors(source, target, /*reportErrors*/ false)) { if (props.length > 5) { // arbitrary cutoff for too-long list form @@ -43799,7 +43812,11 @@ var ts; else { reportError(ts.Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2, typeToString(source), typeToString(target), ts.map(props, function (p) { return symbolToString(p); }).join(", ")); } + if (shouldSkipElaboration) { + overrideNextErrorInfo = errorInfo; + } } + // ELSE: No array like or unmatched property error - just issue top level error (errorInfo = undefined) } return 0 /* False */; } @@ -121965,30 +121982,37 @@ var ts; return undefined; } var typeChecker = program.getTypeChecker(); - var symbol = getSymbolAtLocationForQuickInfo(node, typeChecker); + var nodeForQuickInfo = getNodeForQuickInfo(node); + var symbol = getSymbolAtLocationForQuickInfo(nodeForQuickInfo, typeChecker); if (!symbol || typeChecker.isUnknownSymbol(symbol)) { - var type_2 = shouldGetType(sourceFile, node, position) ? typeChecker.getTypeAtLocation(node) : undefined; + var type_2 = shouldGetType(sourceFile, nodeForQuickInfo, position) ? typeChecker.getTypeAtLocation(nodeForQuickInfo) : undefined; return type_2 && { kind: "" /* unknown */, kindModifiers: "" /* none */, - textSpan: ts.createTextSpanFromNode(node, sourceFile), - displayParts: typeChecker.runWithCancellationToken(cancellationToken, function (typeChecker) { return ts.typeToDisplayParts(typeChecker, type_2, ts.getContainerNode(node)); }), + textSpan: ts.createTextSpanFromNode(nodeForQuickInfo, sourceFile), + displayParts: typeChecker.runWithCancellationToken(cancellationToken, function (typeChecker) { return ts.typeToDisplayParts(typeChecker, type_2, ts.getContainerNode(nodeForQuickInfo)); }), documentation: type_2.symbol ? type_2.symbol.getDocumentationComment(typeChecker) : undefined, tags: type_2.symbol ? type_2.symbol.getJsDocTags() : undefined }; } var _a = typeChecker.runWithCancellationToken(cancellationToken, function (typeChecker) { - return ts.SymbolDisplay.getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, ts.getContainerNode(node), node); + return ts.SymbolDisplay.getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, ts.getContainerNode(nodeForQuickInfo), nodeForQuickInfo); }), symbolKind = _a.symbolKind, displayParts = _a.displayParts, documentation = _a.documentation, tags = _a.tags; return { kind: symbolKind, kindModifiers: ts.SymbolDisplay.getSymbolModifiers(symbol), - textSpan: ts.createTextSpanFromNode(node, sourceFile), + textSpan: ts.createTextSpanFromNode(nodeForQuickInfo, sourceFile), displayParts: displayParts, documentation: documentation, tags: tags, }; } + function getNodeForQuickInfo(node) { + if (ts.isNewExpression(node.parent) && node.pos === node.parent.pos) { + return node.parent.expression; + } + return node; + } function shouldGetType(sourceFile, node, position) { switch (node.kind) { case 73 /* Identifier */: diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js index 62804a617752d..9974b9a33e035 100644 --- a/lib/typescriptServices.js +++ b/lib/typescriptServices.js @@ -3488,7 +3488,7 @@ var ts; /* @internal */ TypeFlags[TypeFlags["ObjectFlagsType"] = 3899392] = "ObjectFlagsType"; /* @internal */ - TypeFlags[TypeFlags["Simplifiable"] = 58720256] = "Simplifiable"; + TypeFlags[TypeFlags["Simplifiable"] = 25165824] = "Simplifiable"; // 'Narrowable' types are types where narrowing actually narrows. // This *should* be every type other than null, undefined, void, and never TypeFlags[TypeFlags["Narrowable"] = 133970943] = "Narrowable"; @@ -40622,8 +40622,7 @@ var ts; function getSimplifiedType(type, writing) { return type.flags & 8388608 /* IndexedAccess */ ? getSimplifiedIndexedAccessType(type, writing) : type.flags & 16777216 /* Conditional */ ? getSimplifiedConditionalType(type, writing) : - type.flags & 33554432 /* Substitution */ ? writing ? type.typeVariable : type.substitute : - type; + type; } function distributeIndexOverObjectType(objectType, indexType, writing) { // (T | U)[K] -> T[K] | U[K] (reading) @@ -42600,7 +42599,7 @@ var ts; var depth = 0; var expandingFlags = 0 /* None */; var overflow = false; - var suppressNextError = false; + var overrideNextErrorInfo; ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking"); var result = isRelatedTo(source, target, /*reportErrors*/ !!errorNode, headMessage); if (overflow) { @@ -42724,10 +42723,16 @@ var ts; if (isFreshLiteralType(target)) { target = target.regularType; } - if (source.flags & 58720256 /* Simplifiable */) { + if (source.flags & 33554432 /* Substitution */) { + source = source.substitute; + } + if (target.flags & 33554432 /* Substitution */) { + target = target.typeVariable; + } + if (source.flags & 25165824 /* Simplifiable */) { source = getSimplifiedType(source, /*writing*/ false); } - if (target.flags & 58720256 /* Simplifiable */) { + if (target.flags & 25165824 /* Simplifiable */) { target = getSimplifiedType(target, /*writing*/ true); } // Try to see if we're relating something like `Foo` -> `Bar | null | undefined`. @@ -42856,10 +42861,14 @@ var ts; } } if (!result && reportErrors) { - var maybeSuppress = suppressNextError; - suppressNextError = false; + var maybeSuppress = overrideNextErrorInfo; + overrideNextErrorInfo = undefined; if (source.flags & 524288 /* Object */ && target.flags & 524288 /* Object */) { + var currentError = errorInfo; tryElaborateArrayLikeErrors(source, target, reportErrors); + if (errorInfo !== currentError) { + maybeSuppress = errorInfo; + } } if (source.flags & 524288 /* Object */ && target.flags & 131068 /* Primitive */) { tryElaborateErrorsForPrimitivesAndObjects(source, target); @@ -43781,9 +43790,10 @@ var ts; if (unmatchedProperty) { if (reportErrors) { var props = ts.arrayFrom(getUnmatchedProperties(source, target, requireOptionalProperties, /*matchDiscriminantProperties*/ false)); + var shouldSkipElaboration = false; if (!headMessage || (headMessage.code !== ts.Diagnostics.Class_0_incorrectly_implements_interface_1.code && headMessage.code !== ts.Diagnostics.Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass.code)) { - suppressNextError = true; // Retain top-level error for interface implementing issues, otherwise omit it + shouldSkipElaboration = true; // Retain top-level error for interface implementing issues, otherwise omit it } if (props.length === 1) { var propName = symbolToString(unmatchedProperty); @@ -43791,6 +43801,9 @@ var ts; if (ts.length(unmatchedProperty.declarations)) { associateRelatedInfo(ts.createDiagnosticForNode(unmatchedProperty.declarations[0], ts.Diagnostics._0_is_declared_here, propName)); } + if (shouldSkipElaboration) { + overrideNextErrorInfo = errorInfo; + } } else if (tryElaborateArrayLikeErrors(source, target, /*reportErrors*/ false)) { if (props.length > 5) { // arbitrary cutoff for too-long list form @@ -43799,7 +43812,11 @@ var ts; else { reportError(ts.Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2, typeToString(source), typeToString(target), ts.map(props, function (p) { return symbolToString(p); }).join(", ")); } + if (shouldSkipElaboration) { + overrideNextErrorInfo = errorInfo; + } } + // ELSE: No array like or unmatched property error - just issue top level error (errorInfo = undefined) } return 0 /* False */; } @@ -121965,30 +121982,37 @@ var ts; return undefined; } var typeChecker = program.getTypeChecker(); - var symbol = getSymbolAtLocationForQuickInfo(node, typeChecker); + var nodeForQuickInfo = getNodeForQuickInfo(node); + var symbol = getSymbolAtLocationForQuickInfo(nodeForQuickInfo, typeChecker); if (!symbol || typeChecker.isUnknownSymbol(symbol)) { - var type_2 = shouldGetType(sourceFile, node, position) ? typeChecker.getTypeAtLocation(node) : undefined; + var type_2 = shouldGetType(sourceFile, nodeForQuickInfo, position) ? typeChecker.getTypeAtLocation(nodeForQuickInfo) : undefined; return type_2 && { kind: "" /* unknown */, kindModifiers: "" /* none */, - textSpan: ts.createTextSpanFromNode(node, sourceFile), - displayParts: typeChecker.runWithCancellationToken(cancellationToken, function (typeChecker) { return ts.typeToDisplayParts(typeChecker, type_2, ts.getContainerNode(node)); }), + textSpan: ts.createTextSpanFromNode(nodeForQuickInfo, sourceFile), + displayParts: typeChecker.runWithCancellationToken(cancellationToken, function (typeChecker) { return ts.typeToDisplayParts(typeChecker, type_2, ts.getContainerNode(nodeForQuickInfo)); }), documentation: type_2.symbol ? type_2.symbol.getDocumentationComment(typeChecker) : undefined, tags: type_2.symbol ? type_2.symbol.getJsDocTags() : undefined }; } var _a = typeChecker.runWithCancellationToken(cancellationToken, function (typeChecker) { - return ts.SymbolDisplay.getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, ts.getContainerNode(node), node); + return ts.SymbolDisplay.getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, ts.getContainerNode(nodeForQuickInfo), nodeForQuickInfo); }), symbolKind = _a.symbolKind, displayParts = _a.displayParts, documentation = _a.documentation, tags = _a.tags; return { kind: symbolKind, kindModifiers: ts.SymbolDisplay.getSymbolModifiers(symbol), - textSpan: ts.createTextSpanFromNode(node, sourceFile), + textSpan: ts.createTextSpanFromNode(nodeForQuickInfo, sourceFile), displayParts: displayParts, documentation: documentation, tags: tags, }; } + function getNodeForQuickInfo(node) { + if (ts.isNewExpression(node.parent) && node.pos === node.parent.pos) { + return node.parent.expression; + } + return node; + } function shouldGetType(sourceFile, node, position) { switch (node.kind) { case 73 /* Identifier */: diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js index a3a1cc432c500..fe566943e2c10 100644 --- a/lib/typingsInstaller.js +++ b/lib/typingsInstaller.js @@ -3489,7 +3489,7 @@ var ts; /* @internal */ TypeFlags[TypeFlags["ObjectFlagsType"] = 3899392] = "ObjectFlagsType"; /* @internal */ - TypeFlags[TypeFlags["Simplifiable"] = 58720256] = "Simplifiable"; + TypeFlags[TypeFlags["Simplifiable"] = 25165824] = "Simplifiable"; // 'Narrowable' types are types where narrowing actually narrows. // This *should* be every type other than null, undefined, void, and never TypeFlags[TypeFlags["Narrowable"] = 133970943] = "Narrowable"; @@ -40623,8 +40623,7 @@ var ts; function getSimplifiedType(type, writing) { return type.flags & 8388608 /* IndexedAccess */ ? getSimplifiedIndexedAccessType(type, writing) : type.flags & 16777216 /* Conditional */ ? getSimplifiedConditionalType(type, writing) : - type.flags & 33554432 /* Substitution */ ? writing ? type.typeVariable : type.substitute : - type; + type; } function distributeIndexOverObjectType(objectType, indexType, writing) { // (T | U)[K] -> T[K] | U[K] (reading) @@ -42601,7 +42600,7 @@ var ts; var depth = 0; var expandingFlags = 0 /* None */; var overflow = false; - var suppressNextError = false; + var overrideNextErrorInfo; ts.Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking"); var result = isRelatedTo(source, target, /*reportErrors*/ !!errorNode, headMessage); if (overflow) { @@ -42725,10 +42724,16 @@ var ts; if (isFreshLiteralType(target)) { target = target.regularType; } - if (source.flags & 58720256 /* Simplifiable */) { + if (source.flags & 33554432 /* Substitution */) { + source = source.substitute; + } + if (target.flags & 33554432 /* Substitution */) { + target = target.typeVariable; + } + if (source.flags & 25165824 /* Simplifiable */) { source = getSimplifiedType(source, /*writing*/ false); } - if (target.flags & 58720256 /* Simplifiable */) { + if (target.flags & 25165824 /* Simplifiable */) { target = getSimplifiedType(target, /*writing*/ true); } // Try to see if we're relating something like `Foo` -> `Bar | null | undefined`. @@ -42857,10 +42862,14 @@ var ts; } } if (!result && reportErrors) { - var maybeSuppress = suppressNextError; - suppressNextError = false; + var maybeSuppress = overrideNextErrorInfo; + overrideNextErrorInfo = undefined; if (source.flags & 524288 /* Object */ && target.flags & 524288 /* Object */) { + var currentError = errorInfo; tryElaborateArrayLikeErrors(source, target, reportErrors); + if (errorInfo !== currentError) { + maybeSuppress = errorInfo; + } } if (source.flags & 524288 /* Object */ && target.flags & 131068 /* Primitive */) { tryElaborateErrorsForPrimitivesAndObjects(source, target); @@ -43782,9 +43791,10 @@ var ts; if (unmatchedProperty) { if (reportErrors) { var props = ts.arrayFrom(getUnmatchedProperties(source, target, requireOptionalProperties, /*matchDiscriminantProperties*/ false)); + var shouldSkipElaboration = false; if (!headMessage || (headMessage.code !== ts.Diagnostics.Class_0_incorrectly_implements_interface_1.code && headMessage.code !== ts.Diagnostics.Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass.code)) { - suppressNextError = true; // Retain top-level error for interface implementing issues, otherwise omit it + shouldSkipElaboration = true; // Retain top-level error for interface implementing issues, otherwise omit it } if (props.length === 1) { var propName = symbolToString(unmatchedProperty); @@ -43792,6 +43802,9 @@ var ts; if (ts.length(unmatchedProperty.declarations)) { associateRelatedInfo(ts.createDiagnosticForNode(unmatchedProperty.declarations[0], ts.Diagnostics._0_is_declared_here, propName)); } + if (shouldSkipElaboration) { + overrideNextErrorInfo = errorInfo; + } } else if (tryElaborateArrayLikeErrors(source, target, /*reportErrors*/ false)) { if (props.length > 5) { // arbitrary cutoff for too-long list form @@ -43800,7 +43813,11 @@ var ts; else { reportError(ts.Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2, typeToString(source), typeToString(target), ts.map(props, function (p) { return symbolToString(p); }).join(", ")); } + if (shouldSkipElaboration) { + overrideNextErrorInfo = errorInfo; + } } + // ELSE: No array like or unmatched property error - just issue top level error (errorInfo = undefined) } return 0 /* False */; }