mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge remote-tracking branch 'origin/master' into release-3.5
This commit is contained in:
+22
-5
@@ -10196,7 +10196,6 @@ namespace ts {
|
||||
function getSimplifiedType(type: Type, writing: boolean): Type {
|
||||
return type.flags & TypeFlags.IndexedAccess ? getSimplifiedIndexedAccessType(<IndexedAccessType>type, writing) :
|
||||
type.flags & TypeFlags.Conditional ? getSimplifiedConditionalType(<ConditionalType>type, writing) :
|
||||
type.flags & TypeFlags.Substitution ? writing ? (<SubstitutionType>type).typeVariable : (<SubstitutionType>type).substitute :
|
||||
type;
|
||||
}
|
||||
|
||||
@@ -12290,7 +12289,7 @@ namespace ts {
|
||||
let depth = 0;
|
||||
let expandingFlags = ExpandingFlags.None;
|
||||
let overflow = false;
|
||||
let suppressNextError = false;
|
||||
let overrideNextErrorInfo: DiagnosticMessageChain | undefined;
|
||||
|
||||
Debug.assert(relation !== identityRelation || !errorNode, "no error reporting in identity checking");
|
||||
|
||||
@@ -12432,6 +12431,12 @@ namespace ts {
|
||||
if (isFreshLiteralType(target)) {
|
||||
target = (<FreshableType>target).regularType;
|
||||
}
|
||||
if (source.flags & TypeFlags.Substitution) {
|
||||
source = (<SubstitutionType>source).substitute;
|
||||
}
|
||||
if (target.flags & TypeFlags.Substitution) {
|
||||
target = (<SubstitutionType>target).typeVariable;
|
||||
}
|
||||
if (source.flags & TypeFlags.Simplifiable) {
|
||||
source = getSimplifiedType(source, /*writing*/ false);
|
||||
}
|
||||
@@ -12571,10 +12576,14 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (!result && reportErrors) {
|
||||
const maybeSuppress = suppressNextError;
|
||||
suppressNextError = false;
|
||||
let maybeSuppress = overrideNextErrorInfo;
|
||||
overrideNextErrorInfo = undefined;
|
||||
if (source.flags & TypeFlags.Object && target.flags & TypeFlags.Object) {
|
||||
const currentError = errorInfo;
|
||||
tryElaborateArrayLikeErrors(source, target, reportErrors);
|
||||
if (errorInfo !== currentError) {
|
||||
maybeSuppress = errorInfo;
|
||||
}
|
||||
}
|
||||
if (source.flags & TypeFlags.Object && target.flags & TypeFlags.Primitive) {
|
||||
tryElaborateErrorsForPrimitivesAndObjects(source, target);
|
||||
@@ -13506,9 +13515,10 @@ namespace ts {
|
||||
if (unmatchedProperty) {
|
||||
if (reportErrors) {
|
||||
const props = arrayFrom(getUnmatchedProperties(source, target, requireOptionalProperties, /*matchDiscriminantProperties*/ false));
|
||||
let shouldSkipElaboration = false;
|
||||
if (!headMessage || (headMessage.code !== Diagnostics.Class_0_incorrectly_implements_interface_1.code &&
|
||||
headMessage.code !== 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) {
|
||||
const propName = symbolToString(unmatchedProperty);
|
||||
@@ -13516,6 +13526,9 @@ namespace ts {
|
||||
if (length(unmatchedProperty.declarations)) {
|
||||
associateRelatedInfo(createDiagnosticForNode(unmatchedProperty.declarations[0], 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
|
||||
@@ -13524,7 +13537,11 @@ namespace ts {
|
||||
else {
|
||||
reportError(Diagnostics.Type_0_is_missing_the_following_properties_from_type_1_Colon_2, typeToString(source), typeToString(target), map(props, p => symbolToString(p)).join(", "));
|
||||
}
|
||||
if (shouldSkipElaboration) {
|
||||
overrideNextErrorInfo = errorInfo;
|
||||
}
|
||||
}
|
||||
// ELSE: No array like or unmatched property error - just issue top level error (errorInfo = undefined)
|
||||
}
|
||||
return Ternary.False;
|
||||
}
|
||||
|
||||
@@ -3967,7 +3967,7 @@ namespace ts {
|
||||
/* @internal */
|
||||
ObjectFlagsType = Nullable | Never | Object | Union | Intersection,
|
||||
/* @internal */
|
||||
Simplifiable = IndexedAccess | Conditional | Substitution,
|
||||
Simplifiable = IndexedAccess | Conditional,
|
||||
// 'Narrowable' types are types where narrowing actually narrows.
|
||||
// This *should* be every type other than null, undefined, void, and never
|
||||
Narrowable = Any | Unknown | StructuredOrInstantiable | StringLike | NumberLike | BigIntLike | BooleanLike | ESSymbol | UniqueESSymbol | NonPrimitive,
|
||||
|
||||
@@ -1467,33 +1467,41 @@ namespace ts {
|
||||
}
|
||||
|
||||
const typeChecker = program.getTypeChecker();
|
||||
const symbol = getSymbolAtLocationForQuickInfo(node, typeChecker);
|
||||
const nodeForQuickInfo = getNodeForQuickInfo(node);
|
||||
const symbol = getSymbolAtLocationForQuickInfo(nodeForQuickInfo, typeChecker);
|
||||
|
||||
if (!symbol || typeChecker.isUnknownSymbol(symbol)) {
|
||||
const type = shouldGetType(sourceFile, node, position) ? typeChecker.getTypeAtLocation(node) : undefined;
|
||||
const type = shouldGetType(sourceFile, nodeForQuickInfo, position) ? typeChecker.getTypeAtLocation(nodeForQuickInfo) : undefined;
|
||||
return type && {
|
||||
kind: ScriptElementKind.unknown,
|
||||
kindModifiers: ScriptElementKindModifier.none,
|
||||
textSpan: createTextSpanFromNode(node, sourceFile),
|
||||
displayParts: typeChecker.runWithCancellationToken(cancellationToken, typeChecker => typeToDisplayParts(typeChecker, type, getContainerNode(node))),
|
||||
textSpan: createTextSpanFromNode(nodeForQuickInfo, sourceFile),
|
||||
displayParts: typeChecker.runWithCancellationToken(cancellationToken, typeChecker => typeToDisplayParts(typeChecker, type, getContainerNode(nodeForQuickInfo))),
|
||||
documentation: type.symbol ? type.symbol.getDocumentationComment(typeChecker) : undefined,
|
||||
tags: type.symbol ? type.symbol.getJsDocTags() : undefined
|
||||
};
|
||||
}
|
||||
|
||||
const { symbolKind, displayParts, documentation, tags } = typeChecker.runWithCancellationToken(cancellationToken, typeChecker =>
|
||||
SymbolDisplay.getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, getContainerNode(node), node)
|
||||
SymbolDisplay.getSymbolDisplayPartsDocumentationAndSymbolKind(typeChecker, symbol, sourceFile, getContainerNode(nodeForQuickInfo), nodeForQuickInfo)
|
||||
);
|
||||
return {
|
||||
kind: symbolKind,
|
||||
kindModifiers: SymbolDisplay.getSymbolModifiers(symbol),
|
||||
textSpan: createTextSpanFromNode(node, sourceFile),
|
||||
textSpan: createTextSpanFromNode(nodeForQuickInfo, sourceFile),
|
||||
displayParts,
|
||||
documentation,
|
||||
tags,
|
||||
};
|
||||
}
|
||||
|
||||
function getNodeForQuickInfo(node: Node): Node {
|
||||
if (isNewExpression(node.parent) && node.pos === node.parent.pos) {
|
||||
return node.parent.expression;
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
function shouldGetType(sourceFile: SourceFile, node: Node, position: number): boolean {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.Identifier:
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
tests/cases/compiler/assigningFunctionToTupleIssuesError.ts(2,5): error TS2322: Type '() => void' is not assignable to type '[string]'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/assigningFunctionToTupleIssuesError.ts (1 errors) ====
|
||||
declare let a: () => void;
|
||||
let b: [string] = a;
|
||||
~
|
||||
!!! error TS2322: Type '() => void' is not assignable to type '[string]'.
|
||||
@@ -0,0 +1,6 @@
|
||||
//// [assigningFunctionToTupleIssuesError.ts]
|
||||
declare let a: () => void;
|
||||
let b: [string] = a;
|
||||
|
||||
//// [assigningFunctionToTupleIssuesError.js]
|
||||
var b = a;
|
||||
@@ -0,0 +1,8 @@
|
||||
=== tests/cases/compiler/assigningFunctionToTupleIssuesError.ts ===
|
||||
declare let a: () => void;
|
||||
>a : Symbol(a, Decl(assigningFunctionToTupleIssuesError.ts, 0, 11))
|
||||
|
||||
let b: [string] = a;
|
||||
>b : Symbol(b, Decl(assigningFunctionToTupleIssuesError.ts, 1, 3))
|
||||
>a : Symbol(a, Decl(assigningFunctionToTupleIssuesError.ts, 0, 11))
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
=== tests/cases/compiler/assigningFunctionToTupleIssuesError.ts ===
|
||||
declare let a: () => void;
|
||||
>a : () => void
|
||||
|
||||
let b: [string] = a;
|
||||
>b : [string]
|
||||
>a : () => void
|
||||
|
||||
@@ -10,13 +10,13 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(24,5): error TS23
|
||||
Type 'keyof B' is not assignable to type 'keyof A'.
|
||||
Type 'string | number | symbol' is not assignable to type 'keyof A'.
|
||||
Type 'string' is not assignable to type 'keyof A'.
|
||||
Type 'string' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf" | keyof A'.
|
||||
Type 'keyof B' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf" | keyof A'.
|
||||
Type 'string | number | symbol' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf" | keyof A'.
|
||||
Type 'string' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf" | keyof A'.
|
||||
Type 'keyof B' is not assignable to type 'keyof A'.
|
||||
Type 'string | number | symbol' is not assignable to type 'keyof A'.
|
||||
Type 'string' is not assignable to type 'keyof A'.
|
||||
Type 'string' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
|
||||
Type 'keyof B' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
|
||||
Type 'string | number | symbol' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
|
||||
Type 'string' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
|
||||
Type 'keyof B' is not assignable to type '"valueOf"'.
|
||||
Type 'string | number | symbol' is not assignable to type '"valueOf"'.
|
||||
Type 'string' is not assignable to type '"valueOf"'.
|
||||
tests/cases/conformance/types/conditional/conditionalTypes2.ts(25,5): error TS2322: Type 'Invariant<A>' is not assignable to type 'Invariant<B>'.
|
||||
Types of property 'foo' are incompatible.
|
||||
Type 'A extends string ? keyof A : A' is not assignable to type 'B extends string ? keyof B : B'.
|
||||
@@ -73,13 +73,13 @@ tests/cases/conformance/types/conditional/conditionalTypes2.ts(75,12): error TS2
|
||||
!!! error TS2322: Type 'keyof B' is not assignable to type 'keyof A'.
|
||||
!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'keyof A'.
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'keyof A'.
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf" | keyof A'.
|
||||
!!! error TS2322: Type 'keyof B' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf" | keyof A'.
|
||||
!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf" | keyof A'.
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf" | keyof A'.
|
||||
!!! error TS2322: Type 'keyof B' is not assignable to type 'keyof A'.
|
||||
!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'keyof A'.
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'keyof A'.
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
|
||||
!!! error TS2322: Type 'keyof B' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
|
||||
!!! error TS2322: Type 'string | number | symbol' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'number | "toString" | "charAt" | "charCodeAt" | "concat" | "indexOf" | "lastIndexOf" | "localeCompare" | "match" | "replace" | "search" | "slice" | "split" | "substring" | "toLowerCase" | "toLocaleLowerCase" | "toUpperCase" | "toLocaleUpperCase" | "trim" | "length" | "substr" | "valueOf"'.
|
||||
!!! error TS2322: Type 'keyof B' is not assignable to type '"valueOf"'.
|
||||
!!! error TS2322: Type 'string | number | symbol' is not assignable to type '"valueOf"'.
|
||||
!!! error TS2322: Type 'string' is not assignable to type '"valueOf"'.
|
||||
b = a; // Error
|
||||
~
|
||||
!!! error TS2322: Type 'Invariant<A>' is not assignable to type 'Invariant<B>'.
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
declare let a: () => void;
|
||||
let b: [string] = a;
|
||||
@@ -0,0 +1,18 @@
|
||||
/// <reference path='fourslash.ts' />
|
||||
|
||||
////class Cat {
|
||||
//// /**
|
||||
//// * NOTE: this constructor is private! Please use the factory function
|
||||
//// */
|
||||
//// private constructor() { }
|
||||
////
|
||||
//// static makeCat() { new Cat(); }
|
||||
////}
|
||||
////
|
||||
////ne/*1*/w Ca/*2*/t();
|
||||
|
||||
verify.quickInfoAt('1', 'constructor Cat(): Cat',
|
||||
'NOTE: this constructor is private! Please use the factory function');
|
||||
|
||||
verify.quickInfoAt('2', 'constructor Cat(): Cat',
|
||||
'NOTE: this constructor is private! Please use the factory function');
|
||||
Reference in New Issue
Block a user