mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-19 10:41:56 -05:00
Cache complex union and intersection relations (#37910)
* Cache complex union/intersection relations * Accept new baselines * Accept new baselines
This commit is contained in:
@@ -202,7 +202,8 @@ namespace ts {
|
||||
Source = 1 << 0,
|
||||
Target = 1 << 1,
|
||||
PropertyCheck = 1 << 2,
|
||||
InPropertyCheck = 1 << 3,
|
||||
UnionIntersectionCheck = 1 << 3,
|
||||
InPropertyCheck = 1 << 4,
|
||||
}
|
||||
|
||||
const enum MappedTypeModifiers {
|
||||
@@ -17010,38 +17011,14 @@ namespace ts {
|
||||
// Note that these checks are specifically ordered to produce correct results. In particular,
|
||||
// we need to deconstruct unions before intersections (because unions are always at the top),
|
||||
// and we need to handle "each" relations before "some" relations for the same kind of type.
|
||||
if (source.flags & TypeFlags.Union) {
|
||||
result = relation === comparableRelation ?
|
||||
someTypeRelatedToType(source as UnionType, target, reportErrors && !(source.flags & TypeFlags.Primitive), intersectionState) :
|
||||
eachTypeRelatedToType(source as UnionType, target, reportErrors && !(source.flags & TypeFlags.Primitive), intersectionState);
|
||||
if (source.flags & TypeFlags.UnionOrIntersection || target.flags & TypeFlags.UnionOrIntersection) {
|
||||
result = getConstituentCount(source) * getConstituentCount(target) >= 4 ?
|
||||
recursiveTypeRelatedTo(source, target, reportErrors, intersectionState | IntersectionState.UnionIntersectionCheck) :
|
||||
structuredTypeRelatedTo(source, target, reportErrors, intersectionState | IntersectionState.UnionIntersectionCheck);
|
||||
}
|
||||
else {
|
||||
if (target.flags & TypeFlags.Union) {
|
||||
result = typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), <UnionType>target, reportErrors && !(source.flags & TypeFlags.Primitive) && !(target.flags & TypeFlags.Primitive));
|
||||
}
|
||||
else if (target.flags & TypeFlags.Intersection) {
|
||||
result = typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target as IntersectionType, reportErrors, IntersectionState.Target);
|
||||
}
|
||||
else if (source.flags & TypeFlags.Intersection) {
|
||||
// Check to see if any constituents of the intersection are immediately related to the target.
|
||||
//
|
||||
// Don't report errors though. Checking whether a constituent is related to the source is not actually
|
||||
// useful and leads to some confusing error messages. Instead it is better to let the below checks
|
||||
// take care of this, or to not elaborate at all. For instance,
|
||||
//
|
||||
// - For an object type (such as 'C = A & B'), users are usually more interested in structural errors.
|
||||
//
|
||||
// - For a union type (such as '(A | B) = (C & D)'), it's better to hold onto the whole intersection
|
||||
// than to report that 'D' is not assignable to 'A' or 'B'.
|
||||
//
|
||||
// - For a primitive type or type parameter (such as 'number = A & B') there is no point in
|
||||
// breaking the intersection apart.
|
||||
result = someTypeRelatedToType(<IntersectionType>source, target, /*reportErrors*/ false, IntersectionState.Source);
|
||||
}
|
||||
if (!result && (source.flags & TypeFlags.StructuredOrInstantiable || target.flags & TypeFlags.StructuredOrInstantiable)) {
|
||||
if (result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState)) {
|
||||
resetErrorInfo(saveErrorInfo);
|
||||
}
|
||||
if (!result && !(source.flags & TypeFlags.Union) && (source.flags & (TypeFlags.StructuredOrInstantiable) || target.flags & TypeFlags.StructuredOrInstantiable)) {
|
||||
if (result = recursiveTypeRelatedTo(source, target, reportErrors, intersectionState)) {
|
||||
resetErrorInfo(saveErrorInfo);
|
||||
}
|
||||
}
|
||||
if (!result && source.flags & (TypeFlags.Intersection | TypeFlags.TypeParameter)) {
|
||||
@@ -17549,6 +17526,37 @@ namespace ts {
|
||||
if (intersectionState & IntersectionState.PropertyCheck) {
|
||||
return propertiesRelatedTo(source, target, reportErrors, /*excludedProperties*/ undefined, IntersectionState.None);
|
||||
}
|
||||
if (intersectionState & IntersectionState.UnionIntersectionCheck) {
|
||||
// Note that these checks are specifically ordered to produce correct results. In particular,
|
||||
// we need to deconstruct unions before intersections (because unions are always at the top),
|
||||
// and we need to handle "each" relations before "some" relations for the same kind of type.
|
||||
if (source.flags & TypeFlags.Union) {
|
||||
return relation === comparableRelation ?
|
||||
someTypeRelatedToType(source as UnionType, target, reportErrors && !(source.flags & TypeFlags.Primitive), intersectionState & ~IntersectionState.UnionIntersectionCheck) :
|
||||
eachTypeRelatedToType(source as UnionType, target, reportErrors && !(source.flags & TypeFlags.Primitive), intersectionState & ~IntersectionState.UnionIntersectionCheck);
|
||||
}
|
||||
if (target.flags & TypeFlags.Union) {
|
||||
return typeRelatedToSomeType(getRegularTypeOfObjectLiteral(source), <UnionType>target, reportErrors && !(source.flags & TypeFlags.Primitive) && !(target.flags & TypeFlags.Primitive));
|
||||
}
|
||||
if (target.flags & TypeFlags.Intersection) {
|
||||
return typeRelatedToEachType(getRegularTypeOfObjectLiteral(source), target as IntersectionType, reportErrors, IntersectionState.Target);
|
||||
}
|
||||
// Source is an intersection. Check to see if any constituents of the intersection are immediately related
|
||||
// to the target.
|
||||
//
|
||||
// Don't report errors though. Checking whether a constituent is related to the source is not actually
|
||||
// useful and leads to some confusing error messages. Instead it is better to let the below checks
|
||||
// take care of this, or to not elaborate at all. For instance,
|
||||
//
|
||||
// - For an object type (such as 'C = A & B'), users are usually more interested in structural errors.
|
||||
//
|
||||
// - For a union type (such as '(A | B) = (C & D)'), it's better to hold onto the whole intersection
|
||||
// than to report that 'D' is not assignable to 'A' or 'B'.
|
||||
//
|
||||
// - For a primitive type or type parameter (such as 'number = A & B') there is no point in
|
||||
// breaking the intersection apart.
|
||||
return someTypeRelatedToType(<IntersectionType>source, target, /*reportErrors*/ false, IntersectionState.Source);
|
||||
}
|
||||
const flags = source.flags & target.flags;
|
||||
if (relation === identityRelation && !(flags & TypeFlags.Object)) {
|
||||
if (flags & TypeFlags.Index) {
|
||||
@@ -21510,6 +21518,10 @@ namespace ts {
|
||||
return mappedTypes && getUnionType(mappedTypes, noReductions ? UnionReduction.None : UnionReduction.Literal);
|
||||
}
|
||||
|
||||
function getConstituentCount(type: Type) {
|
||||
return type.flags & TypeFlags.UnionOrIntersection ? (<UnionOrIntersectionType>type).types.length : 1;
|
||||
}
|
||||
|
||||
function extractTypesOfKind(type: Type, kind: TypeFlags) {
|
||||
return filterType(type, t => (t.flags & kind) !== 0);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(8,5): error TS2416: Prop
|
||||
Type 'string | Derived' is not assignable to type 'string | Base'.
|
||||
Type 'Derived' is not assignable to type 'string | Base'.
|
||||
Type 'Derived' is not assignable to type 'Base'.
|
||||
Types of property 'n' are incompatible.
|
||||
Type 'string | Derived' is not assignable to type 'string | Base'.
|
||||
Type 'Derived' is not assignable to type 'string | Base'.
|
||||
The types returned by 'fn()' are incompatible between these types.
|
||||
Type 'string | number' is not assignable to type 'number'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/compiler/baseClassImprovedMismatchErrors.ts(9,5): error TS2416: Property 'fn' in type 'Derived' is not assignable to the same property in base type 'Base'.
|
||||
Type '() => string | number' is not assignable to type '() => number'.
|
||||
Type 'string | number' is not assignable to type 'number'.
|
||||
@@ -13,9 +13,9 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(14,5): error TS2416: Pro
|
||||
Type 'string | DerivedInterface' is not assignable to type 'string | Base'.
|
||||
Type 'DerivedInterface' is not assignable to type 'string | Base'.
|
||||
Type 'DerivedInterface' is not assignable to type 'Base'.
|
||||
Types of property 'n' are incompatible.
|
||||
Type 'string | DerivedInterface' is not assignable to type 'string | Base'.
|
||||
Type 'DerivedInterface' is not assignable to type 'string | Base'.
|
||||
The types returned by 'fn()' are incompatible between these types.
|
||||
Type 'string | number' is not assignable to type 'number'.
|
||||
Type 'string' is not assignable to type 'number'.
|
||||
tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Property 'fn' in type 'DerivedInterface' is not assignable to the same property in base type 'Base'.
|
||||
Type '() => string | number' is not assignable to type '() => number'.
|
||||
Type 'string | number' is not assignable to type 'number'.
|
||||
@@ -36,9 +36,9 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Pro
|
||||
!!! error TS2416: Type 'string | Derived' is not assignable to type 'string | Base'.
|
||||
!!! error TS2416: Type 'Derived' is not assignable to type 'string | Base'.
|
||||
!!! error TS2416: Type 'Derived' is not assignable to type 'Base'.
|
||||
!!! error TS2416: Types of property 'n' are incompatible.
|
||||
!!! error TS2416: Type 'string | Derived' is not assignable to type 'string | Base'.
|
||||
!!! error TS2416: Type 'Derived' is not assignable to type 'string | Base'.
|
||||
!!! error TS2416: The types returned by 'fn()' are incompatible between these types.
|
||||
!!! error TS2416: Type 'string | number' is not assignable to type 'number'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'number'.
|
||||
fn() {
|
||||
~~
|
||||
!!! error TS2416: Property 'fn' in type 'Derived' is not assignable to the same property in base type 'Base'.
|
||||
@@ -55,9 +55,9 @@ tests/cases/compiler/baseClassImprovedMismatchErrors.ts(15,5): error TS2416: Pro
|
||||
!!! error TS2416: Type 'string | DerivedInterface' is not assignable to type 'string | Base'.
|
||||
!!! error TS2416: Type 'DerivedInterface' is not assignable to type 'string | Base'.
|
||||
!!! error TS2416: Type 'DerivedInterface' is not assignable to type 'Base'.
|
||||
!!! error TS2416: Types of property 'n' are incompatible.
|
||||
!!! error TS2416: Type 'string | DerivedInterface' is not assignable to type 'string | Base'.
|
||||
!!! error TS2416: Type 'DerivedInterface' is not assignable to type 'string | Base'.
|
||||
!!! error TS2416: The types returned by 'fn()' are incompatible between these types.
|
||||
!!! error TS2416: Type 'string | number' is not assignable to type 'number'.
|
||||
!!! error TS2416: Type 'string' is not assignable to type 'number'.
|
||||
fn() {
|
||||
~~
|
||||
!!! error TS2416: Property 'fn' in type 'DerivedInterface' is not assignable to the same property in base type 'Base'.
|
||||
|
||||
@@ -3,7 +3,6 @@ tests/cases/compiler/classPropertyErrorOnNameOnly.ts(7,3): error TS2322: Type '(
|
||||
Type 'undefined' is not assignable to type 'string'.
|
||||
tests/cases/compiler/classPropertyErrorOnNameOnly.ts(24,7): error TS2322: Type '(val: Values) => "1" | "2" | "3" | "4" | "5" | undefined' is not assignable to type 'FuncType'.
|
||||
Type 'string | undefined' is not assignable to type 'string'.
|
||||
Type 'undefined' is not assignable to type 'string'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/classPropertyErrorOnNameOnly.ts (2 errors) ====
|
||||
@@ -38,7 +37,6 @@ tests/cases/compiler/classPropertyErrorOnNameOnly.ts(24,7): error TS2322: Type '
|
||||
~~~~~~~~~~~~
|
||||
!!! error TS2322: Type '(val: Values) => "1" | "2" | "3" | "4" | "5" | undefined' is not assignable to type 'FuncType'.
|
||||
!!! error TS2322: Type 'string | undefined' is not assignable to type 'string'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'string'.
|
||||
switch (val) {
|
||||
case 1:
|
||||
return "1";
|
||||
|
||||
@@ -22,7 +22,6 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(64,33): error
|
||||
Type '"size"' is not assignable to type '"name" | "width" | "height" | "visible"'.
|
||||
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(66,24): error TS2345: Argument of type '"size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'.
|
||||
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(67,24): error TS2345: Argument of type '"name" | "size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'.
|
||||
Type '"size"' is not assignable to type '"name" | "width" | "height" | "visible"'.
|
||||
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(73,5): error TS2536: Type 'keyof T | keyof U' cannot be used to index type 'T | U'.
|
||||
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(74,5): error TS2536: Type 'keyof T | keyof U' cannot be used to index type 'T | U'.
|
||||
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(82,5): error TS2322: Type 'keyof T | keyof U' is not assignable to type 'keyof T & keyof U'.
|
||||
@@ -34,14 +33,8 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(82,5): error
|
||||
Type 'string | number | symbol' is not assignable to type 'keyof U'.
|
||||
Type 'string' is not assignable to type 'keyof U'.
|
||||
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(83,5): error TS2322: Type 'keyof T | keyof U' is not assignable to type 'keyof T & keyof U'.
|
||||
Type 'keyof T' is not assignable to type 'keyof T & keyof U'.
|
||||
Type 'keyof T' is not assignable to type 'keyof U'.
|
||||
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(86,5): error TS2322: Type 'keyof T | keyof U' is not assignable to type 'keyof T & keyof U'.
|
||||
Type 'keyof T' is not assignable to type 'keyof T & keyof U'.
|
||||
Type 'keyof T' is not assignable to type 'keyof U'.
|
||||
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(87,5): error TS2322: Type 'keyof T | keyof U' is not assignable to type 'keyof T & keyof U'.
|
||||
Type 'keyof T' is not assignable to type 'keyof T & keyof U'.
|
||||
Type 'keyof T' is not assignable to type 'keyof U'.
|
||||
tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(103,9): error TS2322: Type 'Extract<keyof T, string>' is not assignable to type 'K'.
|
||||
'Extract<keyof T, string>' is assignable to the constraint of type 'K', but 'K' could be instantiated with a different subtype of constraint 'string'.
|
||||
Type 'string & keyof T' is not assignable to type 'K'.
|
||||
@@ -191,7 +184,6 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(142,5): error
|
||||
setProperty(shape, cond ? "name" : "size", 10); // Error
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '"name" | "size"' is not assignable to parameter of type '"name" | "width" | "height" | "visible"'.
|
||||
!!! error TS2345: Type '"size"' is not assignable to type '"name" | "width" | "height" | "visible"'.
|
||||
}
|
||||
|
||||
function f20<T, U>(x: T | U, y: T & U, k1: keyof (T | U), k2: keyof T & keyof U, k3: keyof (T & U), k4: keyof T | keyof U) {
|
||||
@@ -223,20 +215,14 @@ tests/cases/conformance/types/keyof/keyofAndIndexedAccessErrors.ts(142,5): error
|
||||
k1 = k4; // Error
|
||||
~~
|
||||
!!! error TS2322: Type 'keyof T | keyof U' is not assignable to type 'keyof T & keyof U'.
|
||||
!!! error TS2322: Type 'keyof T' is not assignable to type 'keyof T & keyof U'.
|
||||
!!! error TS2322: Type 'keyof T' is not assignable to type 'keyof U'.
|
||||
|
||||
k2 = k1;
|
||||
k2 = k3; // Error
|
||||
~~
|
||||
!!! error TS2322: Type 'keyof T | keyof U' is not assignable to type 'keyof T & keyof U'.
|
||||
!!! error TS2322: Type 'keyof T' is not assignable to type 'keyof T & keyof U'.
|
||||
!!! error TS2322: Type 'keyof T' is not assignable to type 'keyof U'.
|
||||
k2 = k4; // Error
|
||||
~~
|
||||
!!! error TS2322: Type 'keyof T | keyof U' is not assignable to type 'keyof T & keyof U'.
|
||||
!!! error TS2322: Type 'keyof T' is not assignable to type 'keyof T & keyof U'.
|
||||
!!! error TS2322: Type 'keyof T' is not assignable to type 'keyof U'.
|
||||
|
||||
k3 = k1;
|
||||
k3 = k2;
|
||||
|
||||
@@ -1,51 +1,30 @@
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(3,32): error TS2344: Type 'boolean | undefined' does not satisfy the constraint 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(12,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(13,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(14,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(15,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(16,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(17,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(18,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(19,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(20,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(21,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(22,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(23,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(24,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(25,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(38,1): error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(39,1): error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(40,1): error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(41,1): error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(46,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(47,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(48,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(49,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(50,7): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(55,5): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(63,5): error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
Type 'undefined' is not assignable to type 'boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(79,7): error TS2322: Type 'number | boolean | undefined' is not assignable to type 'number | boolean'.
|
||||
Type 'undefined' is not assignable to type 'number | boolean'.
|
||||
tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(85,1): error TS2322: Type 'undefined' is not assignable to type 'string'.
|
||||
@@ -76,59 +55,45 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(99,11): error TS232
|
||||
const e1: boolean = strMap["foo"];
|
||||
~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
const e2: boolean = strMap.bar;
|
||||
~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
const e3: boolean = strMap[0];
|
||||
~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
const e4: boolean = strMap[0 as string | number];
|
||||
~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
const e5: boolean = strMap[0 as string | 0 | 1];
|
||||
~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
const e6: boolean = strMap[0 as 0 | 1];
|
||||
~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
const e7: boolean = strMap["foo" as "foo" | "baz"];
|
||||
~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
const e8: boolean = strMap[NumericEnum1.A];
|
||||
~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
const e9: boolean = strMap[NumericEnum2.A];
|
||||
~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
const e10: boolean = strMap[StringEnum1.A];
|
||||
~~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
const e11: boolean = strMap[StringEnum1.A as StringEnum1];
|
||||
~~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
const e12: boolean = strMap[NumericEnum1.A as NumericEnum1];
|
||||
~~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
const e13: boolean = strMap[NumericEnum2.A as NumericEnum2];
|
||||
~~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
const e14: boolean = strMap[null as any];
|
||||
~~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
|
||||
// Should be OK
|
||||
const ok1: boolean | undefined = strMap["foo"];
|
||||
@@ -160,23 +125,18 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(99,11): error TS232
|
||||
const num_ok1: boolean = numMap[0];
|
||||
~~~~~~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
const num_ok2: boolean = numMap[0 as number];
|
||||
~~~~~~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
const num_ok3: boolean = numMap[0 as 0 | 1];
|
||||
~~~~~~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
const num_ok4: boolean = numMap[NumericEnum1.A];
|
||||
~~~~~~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
const num_ok5: boolean = numMap[NumericEnum2.A];
|
||||
~~~~~~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
|
||||
// Generics
|
||||
function generic1<T extends { [s: string]: boolean }>(arg: T): boolean {
|
||||
@@ -184,7 +144,6 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(99,11): error TS232
|
||||
return arg["blah"];
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
}
|
||||
function generic2<T extends { [s: string]: boolean }>(arg: T): boolean {
|
||||
// Should OK
|
||||
@@ -195,7 +154,6 @@ tests/cases/conformance/pedantic/noUncheckedIndexedAccess.ts(99,11): error TS232
|
||||
return strMap[arg];
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2322: Type 'boolean | undefined' is not assignable to type 'boolean'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'boolean'.
|
||||
}
|
||||
|
||||
// Element access into known properties is ok
|
||||
|
||||
@@ -5,7 +5,6 @@ tests/cases/conformance/types/spread/objectSpreadStrictNull.ts(14,9): error TS23
|
||||
tests/cases/conformance/types/spread/objectSpreadStrictNull.ts(15,9): error TS2322: Type '{ sn: number | undefined; }' is not assignable to type '{ sn: string | number; }'.
|
||||
Types of property 'sn' are incompatible.
|
||||
Type 'number | undefined' is not assignable to type 'string | number'.
|
||||
Type 'undefined' is not assignable to type 'string | number'.
|
||||
tests/cases/conformance/types/spread/objectSpreadStrictNull.ts(18,9): error TS2322: Type '{ sn: string | number | undefined; }' is not assignable to type '{ sn: string | number | boolean; }'.
|
||||
Types of property 'sn' are incompatible.
|
||||
Type 'string | number | undefined' is not assignable to type 'string | number | boolean'.
|
||||
@@ -42,7 +41,6 @@ tests/cases/conformance/types/spread/objectSpreadStrictNull.ts(42,5): error TS23
|
||||
!!! error TS2322: Type '{ sn: number | undefined; }' is not assignable to type '{ sn: string | number; }'.
|
||||
!!! error TS2322: Types of property 'sn' are incompatible.
|
||||
!!! error TS2322: Type 'number | undefined' is not assignable to type 'string | number'.
|
||||
!!! error TS2322: Type 'undefined' is not assignable to type 'string | number'.
|
||||
let allUndefined: { sn: string | number | undefined } = { ...undefinedString, ...undefinedNumber };
|
||||
|
||||
let undefinedWithOptionalContinues: { sn: string | number | boolean } = { ...definiteBoolean, ...undefinedString, ...optionalNumber };
|
||||
|
||||
@@ -5,7 +5,6 @@ tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx(27,36): error TS2769:
|
||||
Type 'void' is not assignable to type 'boolean'.
|
||||
Overload 2 of 2, '(props: Props, context?: any): FieldFeedback<Props>', gave the following error.
|
||||
Type '(value: string) => void' is not assignable to type '"a" | "b" | ((value: string) => boolean) | undefined'.
|
||||
Type '(value: string) => void' is not assignable to type '(value: string) => boolean'.
|
||||
tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx(43,41): error TS2769: No overload matches this call.
|
||||
Overload 1 of 2, '(props: Readonly<Props>): FieldFeedbackBeta<Props>', gave the following error.
|
||||
Type '(value: string) => void' is not assignable to type '"a" | "b" | ((value: string) => boolean) | undefined'.
|
||||
@@ -13,7 +12,6 @@ tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx(43,41): error TS2769:
|
||||
Type 'void' is not assignable to type 'boolean'.
|
||||
Overload 2 of 2, '(props: Props, context?: any): FieldFeedbackBeta<Props>', gave the following error.
|
||||
Type '(value: string) => void' is not assignable to type '"a" | "b" | ((value: string) => boolean) | undefined'.
|
||||
Type '(value: string) => void' is not assignable to type '(value: string) => boolean'.
|
||||
tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx(64,37): error TS2769: No overload matches this call.
|
||||
Overload 1 of 2, '(props: Readonly<MyPropsProps>): FieldFeedback2<MyPropsProps>', gave the following error.
|
||||
Type '(value: string) => void' is not assignable to type '(value: string) => boolean'.
|
||||
@@ -58,7 +56,6 @@ tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx(64,37): error TS2769:
|
||||
!!! error TS2769: Type 'void' is not assignable to type 'boolean'.
|
||||
!!! error TS2769: Overload 2 of 2, '(props: Props, context?: any): FieldFeedback<Props>', gave the following error.
|
||||
!!! error TS2769: Type '(value: string) => void' is not assignable to type '"a" | "b" | ((value: string) => boolean) | undefined'.
|
||||
!!! error TS2769: Type '(value: string) => void' is not assignable to type '(value: string) => boolean'.
|
||||
!!! related TS6500 tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx:6:3: The expected type comes from property 'when' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<FieldFeedback<Props>> & Pick<Readonly<{ children?: ReactNode; }> & Readonly<Props>, "children" | "error"> & Partial<Pick<Readonly<{ children?: ReactNode; }> & Readonly<Props>, "when">> & Partial<Pick<{ when: () => boolean; }, never>>'
|
||||
!!! related TS6500 tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx:6:3: The expected type comes from property 'when' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<FieldFeedback<Props>> & Pick<Readonly<{ children?: ReactNode; }> & Readonly<Props>, "children" | "error"> & Partial<Pick<Readonly<{ children?: ReactNode; }> & Readonly<Props>, "when">> & Partial<Pick<{ when: () => boolean; }, never>>'
|
||||
|
||||
@@ -85,7 +82,6 @@ tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx(64,37): error TS2769:
|
||||
!!! error TS2769: Type 'void' is not assignable to type 'boolean'.
|
||||
!!! error TS2769: Overload 2 of 2, '(props: Props, context?: any): FieldFeedbackBeta<Props>', gave the following error.
|
||||
!!! error TS2769: Type '(value: string) => void' is not assignable to type '"a" | "b" | ((value: string) => boolean) | undefined'.
|
||||
!!! error TS2769: Type '(value: string) => void' is not assignable to type '(value: string) => boolean'.
|
||||
!!! related TS6500 tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx:6:3: The expected type comes from property 'when' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<FieldFeedbackBeta<Props>> & Pick<Readonly<{ children?: ReactNode; }> & Readonly<Props>, "children"> & Partial<Pick<Readonly<{ children?: ReactNode; }> & Readonly<Props>, "when" | "error">> & Partial<Pick<BaseProps, never>>'
|
||||
!!! related TS6500 tests/cases/compiler/reactDefaultPropsInferenceSuccess.tsx:6:3: The expected type comes from property 'when' which is declared here on type 'IntrinsicAttributes & IntrinsicClassAttributes<FieldFeedbackBeta<Props>> & Pick<Readonly<{ children?: ReactNode; }> & Readonly<Props>, "children"> & Partial<Pick<Readonly<{ children?: ReactNode; }> & Readonly<Props>, "when" | "error">> & Partial<Pick<BaseProps, never>>'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user