Merge pull request #14991 from Microsoft/fixTypeRelationStackOverflow

Fix type relation stack overflow
This commit is contained in:
Anders Hejlsberg
2017-04-04 20:28:16 -07:00
committed by GitHub
13 changed files with 374 additions and 268 deletions

View File

@@ -8538,137 +8538,38 @@ namespace ts {
return result;
}
}
else if (target.flags & TypeFlags.Union) {
if (result = typeRelatedToSomeType(source, <UnionType>target, reportErrors && !(source.flags & TypeFlags.Primitive) && !(target.flags & TypeFlags.Primitive))) {
return result;
}
}
else if (target.flags & TypeFlags.Intersection) {
if (result = typeRelatedToEachType(source, target as IntersectionType, reportErrors)) {
return result;
}
}
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.
if (result = someTypeRelatedToType(<IntersectionType>source, target, /*reportErrors*/ false)) {
return result;
}
}
else if (target.flags & TypeFlags.TypeParameter) {
// A source type { [P in keyof T]: X } is related to a target type T if X is related to T[P].
if (getObjectFlags(source) & ObjectFlags.Mapped && getConstraintTypeFromMappedType(<MappedType>source) === getIndexType(target)) {
if (!(<MappedType>source).declaration.questionToken) {
const templateType = getTemplateTypeFromMappedType(<MappedType>source);
const indexedAccessType = getIndexedAccessType(target, getTypeParameterFromMappedType(<MappedType>source));
if (result = isRelatedTo(templateType, indexedAccessType, reportErrors)) {
return result;
}
}
}
}
else if (target.flags & TypeFlags.Index) {
// A keyof S is related to a keyof T if T is related to S.
if (source.flags & TypeFlags.Index) {
if (result = isRelatedTo((<IndexType>target).type, (<IndexType>source).type, /*reportErrors*/ false)) {
return result;
}
}
// A type S is assignable to keyof T if S is assignable to keyof C, where C is the
// constraint of T.
const constraint = getConstraintOfType((<IndexType>target).type);
if (constraint) {
if (result = isRelatedTo(source, getIndexType(constraint), reportErrors)) {
return result;
}
}
}
else if (target.flags & TypeFlags.IndexedAccess) {
// A type S is related to a type T[K] if S is related to A[K], where K is string-like and
// A is the apparent type of S.
const constraint = getConstraintOfType(<IndexedAccessType>target);
if (constraint) {
if (result = isRelatedTo(source, constraint, reportErrors)) {
errorInfo = saveErrorInfo;
return result;
}
}
}
if (source.flags & TypeFlags.TypeParameter) {
// A source type T is related to a target type { [P in keyof T]: X } if T[P] is related to X.
if (getObjectFlags(target) & ObjectFlags.Mapped && getConstraintTypeFromMappedType(<MappedType>target) === getIndexType(source)) {
const indexedAccessType = getIndexedAccessType(source, getTypeParameterFromMappedType(<MappedType>target));
const templateType = getTemplateTypeFromMappedType(<MappedType>target);
if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) {
errorInfo = saveErrorInfo;
return result;
}
}
else {
let constraint = getConstraintOfTypeParameter(<TypeParameter>source);
// A type parameter with no constraint is not related to the non-primitive object type.
if (constraint || !(target.flags & TypeFlags.NonPrimitive)) {
if (!constraint || constraint.flags & TypeFlags.Any) {
constraint = emptyObjectType;
}
// The constraint may need to be further instantiated with its 'this' type.
constraint = getTypeWithThisArgument(constraint, source);
// Report constraint errors only if the constraint is not the empty object type
const reportConstraintErrors = reportErrors && constraint !== emptyObjectType;
if (result = isRelatedTo(constraint, target, reportConstraintErrors)) {
errorInfo = saveErrorInfo;
return result;
}
}
}
}
else if (source.flags & TypeFlags.IndexedAccess) {
// A type S[K] is related to a type T if A[K] is related to T, where K is string-like and
// A is the apparent type of S.
const constraint = getConstraintOfType(<IndexedAccessType>source);
if (constraint) {
if (result = isRelatedTo(constraint, target, reportErrors)) {
errorInfo = saveErrorInfo;
return result;
}
}
else if (target.flags & TypeFlags.IndexedAccess && (<IndexedAccessType>source).indexType === (<IndexedAccessType>target).indexType) {
// if we have indexed access types with identical index types, see if relationship holds for
// the two object types.
if (result = isRelatedTo((<IndexedAccessType>source).objectType, (<IndexedAccessType>target).objectType, reportErrors)) {
return result;
}
}
}
else {
if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && (<TypeReference>source).target === (<TypeReference>target).target) {
// We have type references to same target type, see if relationship holds for all type arguments
if (result = typeArgumentsRelatedTo(<TypeReference>source, <TypeReference>target, reportErrors)) {
if (target.flags & TypeFlags.Union) {
if (result = typeRelatedToSomeType(source, <UnionType>target, reportErrors && !(source.flags & TypeFlags.Primitive) && !(target.flags & TypeFlags.Primitive))) {
return result;
}
}
// Even if relationship doesn't hold for unions, intersections, or generic type references,
// it may hold in a structural comparison.
const apparentSource = getApparentType(source);
// In a check of the form X = A & B, we will have previously checked if A relates to X or B relates
// to X. Failing both of those we want to check if the aggregation of A and B's members structurally
// relates to X. Thus, we include intersection types on the source side here.
if (apparentSource.flags & (TypeFlags.Object | TypeFlags.Intersection) && target.flags & TypeFlags.Object) {
// Report structural errors only if we haven't reported any errors yet
const reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo && !(source.flags & TypeFlags.Primitive);
if (result = objectTypeRelatedTo(apparentSource, source, target, reportStructuralErrors)) {
else if (target.flags & TypeFlags.Intersection) {
if (result = typeRelatedToEachType(source, target as IntersectionType, reportErrors)) {
return result;
}
}
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.
if (result = someTypeRelatedToType(<IntersectionType>source, target, /*reportErrors*/ false)) {
return result;
}
}
if (source.flags & TypeFlags.StructuredOrTypeVariable || target.flags & TypeFlags.StructuredOrTypeVariable) {
if (result = recursiveTypeRelatedTo(source, target, reportErrors)) {
errorInfo = saveErrorInfo;
return result;
}
@@ -8690,13 +8591,7 @@ namespace ts {
function isIdenticalTo(source: Type, target: Type): Ternary {
let result: Ternary;
if (source.flags & TypeFlags.Object && target.flags & TypeFlags.Object) {
if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && (<TypeReference>source).target === (<TypeReference>target).target) {
// We have type references to same target type, see if all type arguments are identical
if (result = typeArgumentsRelatedTo(<TypeReference>source, <TypeReference>target, /*reportErrors*/ false)) {
return result;
}
}
return objectTypeRelatedTo(source, source, target, /*reportErrors*/ false);
return recursiveTypeRelatedTo(source, target, /*reportErrors*/ false);
}
if (source.flags & TypeFlags.Union && target.flags & TypeFlags.Union ||
source.flags & TypeFlags.Intersection && target.flags & TypeFlags.Intersection) {
@@ -8885,12 +8780,12 @@ namespace ts {
return result;
}
// Determine if two object types are related by structure. First, check if the result is already available in the global cache.
// Determine if possibly recursive types are related. First, check if the result is already available in the global cache.
// Second, check if we have already started a comparison of the given two types in which case we assume the result to be true.
// Third, check if both types are part of deeply nested chains of generic type instantiations and if so assume the types are
// equal and infinitely expanding. Fourth, if we have reached a depth of 100 nested comparisons, assume we have runaway recursion
// and issue an error. Otherwise, actually compare the structure of the two types.
function objectTypeRelatedTo(source: Type, originalSource: Type, target: Type, reportErrors: boolean): Ternary {
function recursiveTypeRelatedTo(source: Type, target: Type, reportErrors: boolean): Ternary {
if (overflow) {
return Ternary.False;
}
@@ -8932,28 +8827,7 @@ namespace ts {
const saveExpandingFlags = expandingFlags;
if (!(expandingFlags & 1) && isDeeplyNestedType(source, sourceStack, depth)) expandingFlags |= 1;
if (!(expandingFlags & 2) && isDeeplyNestedType(target, targetStack, depth)) expandingFlags |= 2;
let result: Ternary;
if (expandingFlags === 3) {
result = Ternary.Maybe;
}
else if (isGenericMappedType(source) || isGenericMappedType(target)) {
result = mappedTypeRelatedTo(source, target, reportErrors);
}
else {
result = propertiesRelatedTo(source, target, reportErrors);
if (result) {
result &= signaturesRelatedTo(source, target, SignatureKind.Call, reportErrors);
if (result) {
result &= signaturesRelatedTo(source, target, SignatureKind.Construct, reportErrors);
if (result) {
result &= indexTypesRelatedTo(source, originalSource, target, IndexKind.String, reportErrors);
if (result) {
result &= indexTypesRelatedTo(source, originalSource, target, IndexKind.Number, reportErrors);
}
}
}
}
}
const result = expandingFlags !== 3 ? structuredTypeRelatedTo(source, target, reportErrors) : Ternary.Maybe;
expandingFlags = saveExpandingFlags;
depth--;
if (result) {
@@ -8970,6 +8844,141 @@ namespace ts {
return result;
}
function structuredTypeRelatedTo(source: Type, target: Type, reportErrors: boolean): Ternary {
let result: Ternary;
const saveErrorInfo = errorInfo;
if (target.flags & TypeFlags.TypeParameter) {
// A source type { [P in keyof T]: X } is related to a target type T if X is related to T[P].
if (getObjectFlags(source) & ObjectFlags.Mapped && getConstraintTypeFromMappedType(<MappedType>source) === getIndexType(target)) {
if (!(<MappedType>source).declaration.questionToken) {
const templateType = getTemplateTypeFromMappedType(<MappedType>source);
const indexedAccessType = getIndexedAccessType(target, getTypeParameterFromMappedType(<MappedType>source));
if (result = isRelatedTo(templateType, indexedAccessType, reportErrors)) {
return result;
}
}
}
}
else if (target.flags & TypeFlags.Index) {
// A keyof S is related to a keyof T if T is related to S.
if (source.flags & TypeFlags.Index) {
if (result = isRelatedTo((<IndexType>target).type, (<IndexType>source).type, /*reportErrors*/ false)) {
return result;
}
}
// A type S is assignable to keyof T if S is assignable to keyof C, where C is the
// constraint of T.
const constraint = getConstraintOfType((<IndexType>target).type);
if (constraint) {
if (result = isRelatedTo(source, getIndexType(constraint), reportErrors)) {
return result;
}
}
}
else if (target.flags & TypeFlags.IndexedAccess) {
// A type S is related to a type T[K] if S is related to A[K], where K is string-like and
// A is the apparent type of S.
const constraint = getConstraintOfType(<IndexedAccessType>target);
if (constraint) {
if (result = isRelatedTo(source, constraint, reportErrors)) {
errorInfo = saveErrorInfo;
return result;
}
}
}
if (source.flags & TypeFlags.TypeParameter) {
// A source type T is related to a target type { [P in keyof T]: X } if T[P] is related to X.
if (getObjectFlags(target) & ObjectFlags.Mapped && getConstraintTypeFromMappedType(<MappedType>target) === getIndexType(source)) {
const indexedAccessType = getIndexedAccessType(source, getTypeParameterFromMappedType(<MappedType>target));
const templateType = getTemplateTypeFromMappedType(<MappedType>target);
if (result = isRelatedTo(indexedAccessType, templateType, reportErrors)) {
errorInfo = saveErrorInfo;
return result;
}
}
else {
let constraint = getConstraintOfTypeParameter(<TypeParameter>source);
// A type parameter with no constraint is not related to the non-primitive object type.
if (constraint || !(target.flags & TypeFlags.NonPrimitive)) {
if (!constraint || constraint.flags & TypeFlags.Any) {
constraint = emptyObjectType;
}
// The constraint may need to be further instantiated with its 'this' type.
constraint = getTypeWithThisArgument(constraint, source);
// Report constraint errors only if the constraint is not the empty object type
const reportConstraintErrors = reportErrors && constraint !== emptyObjectType;
if (result = isRelatedTo(constraint, target, reportConstraintErrors)) {
errorInfo = saveErrorInfo;
return result;
}
}
}
}
else if (source.flags & TypeFlags.IndexedAccess) {
// A type S[K] is related to a type T if A[K] is related to T, where K is string-like and
// A is the apparent type of S.
const constraint = getConstraintOfType(<IndexedAccessType>source);
if (constraint) {
if (result = isRelatedTo(constraint, target, reportErrors)) {
errorInfo = saveErrorInfo;
return result;
}
}
else if (target.flags & TypeFlags.IndexedAccess && (<IndexedAccessType>source).indexType === (<IndexedAccessType>target).indexType) {
// if we have indexed access types with identical index types, see if relationship holds for
// the two object types.
if (result = isRelatedTo((<IndexedAccessType>source).objectType, (<IndexedAccessType>target).objectType, reportErrors)) {
return result;
}
}
}
else {
if (getObjectFlags(source) & ObjectFlags.Reference && getObjectFlags(target) & ObjectFlags.Reference && (<TypeReference>source).target === (<TypeReference>target).target) {
// We have type references to same target type, see if relationship holds for all type arguments
if (result = typeArgumentsRelatedTo(<TypeReference>source, <TypeReference>target, reportErrors)) {
return result;
}
}
// Even if relationship doesn't hold for unions, intersections, or generic type references,
// it may hold in a structural comparison.
const sourceIsPrimitive = !!(source.flags & TypeFlags.Primitive);
if (relation !== identityRelation) {
source = getApparentType(source);
}
// In a check of the form X = A & B, we will have previously checked if A relates to X or B relates
// to X. Failing both of those we want to check if the aggregation of A and B's members structurally
// relates to X. Thus, we include intersection types on the source side here.
if (source.flags & (TypeFlags.Object | TypeFlags.Intersection) && target.flags & TypeFlags.Object) {
// Report structural errors only if we haven't reported any errors yet
const reportStructuralErrors = reportErrors && errorInfo === saveErrorInfo && !sourceIsPrimitive;
if (isGenericMappedType(source) || isGenericMappedType(target)) {
result = mappedTypeRelatedTo(source, target, reportStructuralErrors);
}
else {
result = propertiesRelatedTo(source, target, reportStructuralErrors);
if (result) {
result &= signaturesRelatedTo(source, target, SignatureKind.Call, reportStructuralErrors);
if (result) {
result &= signaturesRelatedTo(source, target, SignatureKind.Construct, reportStructuralErrors);
if (result) {
result &= indexTypesRelatedTo(source, target, IndexKind.String, sourceIsPrimitive, reportStructuralErrors);
if (result) {
result &= indexTypesRelatedTo(source, target, IndexKind.Number, sourceIsPrimitive, reportStructuralErrors);
}
}
}
}
}
if (result) {
errorInfo = saveErrorInfo;
return result;
}
}
}
return Ternary.False;
}
// A type [P in S]: X is related to a type [Q in T]: Y if T is related to S and X' is
// related to Y, where X' is an instantiation of X in which P is replaced with Q. Notice
// that S and T are contra-variant whereas X and Y are co-variant.
@@ -9218,12 +9227,12 @@ namespace ts {
return related;
}
function indexTypesRelatedTo(source: Type, originalSource: Type, target: Type, kind: IndexKind, reportErrors: boolean) {
function indexTypesRelatedTo(source: Type, target: Type, kind: IndexKind, sourceIsPrimitive: boolean, reportErrors: boolean) {
if (relation === identityRelation) {
return indexTypesIdenticalTo(source, target, kind);
}
const targetInfo = getIndexInfoOfType(target, kind);
if (!targetInfo || ((targetInfo.type.flags & TypeFlags.Any) && !(originalSource.flags & TypeFlags.Primitive))) {
if (!targetInfo || targetInfo.type.flags & TypeFlags.Any && !sourceIsPrimitive) {
// Index signature of type any permits assignment from everything but primitives
return Ternary.True;
}

View File

@@ -8,7 +8,6 @@ tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(18,1): error T
Types of property 'concat' are incompatible.
Type '{ (...items: A[][]): A[]; (...items: (A | A[])[]): A[]; }' is not assignable to type '{ <U extends ReadonlyArray<B>>(...items: U[]): B[]; (...items: B[][]): B[]; (...items: (B | B[])[]): B[]; }'.
Type 'A[]' is not assignable to type 'B[]'.
Type 'A' is not assignable to type 'B'.
==== tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts (2 errors) ====
@@ -42,5 +41,4 @@ tests/cases/compiler/arrayOfSubtypeIsAssignableToReadonlyArray.ts(18,1): error T
!!! error TS2322: Types of property 'concat' are incompatible.
!!! error TS2322: Type '{ (...items: A[][]): A[]; (...items: (A | A[])[]): A[]; }' is not assignable to type '{ <U extends ReadonlyArray<B>>(...items: U[]): B[]; (...items: B[][]): B[]; (...items: (B | B[])[]): B[]; }'.
!!! error TS2322: Type 'A[]' is not assignable to type 'B[]'.
!!! error TS2322: Type 'A' is not assignable to type 'B'.

View File

@@ -1,34 +1,30 @@
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(11,5): error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'.
Type 'T[string]' is not assignable to type 'U[keyof T]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
Type 'T[keyof T]' is not assignable to type 'U[string]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
Type 'T[keyof T]' is not assignable to type 'U[string]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(16,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K]'.
Type 'T[string]' is not assignable to type 'U[K]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
Type 'T[K]' is not assignable to type 'U[string]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
Type 'T[K]' is not assignable to type 'U[string]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(20,5): error TS2536: Type 'keyof U' cannot be used to index type 'T'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(21,5): error TS2322: Type 'T[keyof U]' is not assignable to type 'U[keyof U]'.
Type 'T[string]' is not assignable to type 'U[keyof U]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
Type 'T[keyof U]' is not assignable to type 'U[string]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
Type 'T[keyof U]' is not assignable to type 'U[string]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(21,12): error TS2536: Type 'keyof U' cannot be used to index type 'T'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(25,5): error TS2536: Type 'K' cannot be used to index type 'T'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(26,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K]'.
Type 'T[string]' is not assignable to type 'U[K]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
Type 'T[K]' is not assignable to type 'U[string]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
Type 'T[K]' is not assignable to type 'U[string]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(26,12): error TS2536: Type 'K' cannot be used to index type 'T'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(30,5): error TS2322: Type 'T[keyof T] | undefined' is not assignable to type 'T[keyof T]'.
Type 'undefined' is not assignable to type 'T[keyof T]'.
@@ -42,30 +38,24 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(40,5): error TS2
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(41,5): error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T] | undefined'.
Type 'T[string]' is not assignable to type 'U[keyof T] | undefined'.
Type 'T[string]' is not assignable to type 'U[keyof T]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
Type 'T[keyof T]' is not assignable to type 'U[keyof T]'.
Type 'T[string]' is not assignable to type 'U[keyof T]'.
Type 'T[keyof T]' is not assignable to type 'U[keyof T]'.
Type 'T[string]' is not assignable to type 'U[keyof T]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T[keyof T]' is not assignable to type 'U[string]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
Type 'T[keyof T]' is not assignable to type 'U[string]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(45,5): error TS2322: Type 'U[K] | undefined' is not assignable to type 'T[K]'.
Type 'undefined' is not assignable to type 'T[K]'.
Type 'undefined' is not assignable to type 'T[string]'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(46,5): error TS2322: Type 'T[K]' is not assignable to type 'U[K] | undefined'.
Type 'T[string]' is not assignable to type 'U[K] | undefined'.
Type 'T[string]' is not assignable to type 'U[K]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
Type 'T[K]' is not assignable to type 'U[K]'.
Type 'T[string]' is not assignable to type 'U[K]'.
Type 'T[K]' is not assignable to type 'U[K]'.
Type 'T[string]' is not assignable to type 'U[K]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T[K]' is not assignable to type 'U[string]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
Type 'T[K]' is not assignable to type 'U[string]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(51,5): error TS2542: Index signature in type 'Readonly<T>' only permits reading.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(56,5): error TS2542: Index signature in type 'Readonly<T>' only permits reading.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(61,5): error TS2542: Index signature in type 'Readonly<U>' only permits reading.
@@ -77,10 +67,9 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(141,5): error TS
Type 'T[P]' is not assignable to type 'U[P]'.
Type 'T[string]' is not assignable to type 'U[P]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
Type 'T[P]' is not assignable to type 'U[string]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
Type 'T[P]' is not assignable to type 'U[string]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(146,5): error TS2322: Type '{ [P in keyof T]: T[P]; }' is not assignable to type '{ [P in keyof U]: U[P]; }'.
Type 'keyof U' is not assignable to type 'keyof T'.
tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(151,5): error TS2322: Type '{ [P in K]: T[P]; }' is not assignable to type '{ [P in keyof T]: T[P]; }'.
@@ -93,10 +82,9 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(166,5): error TS
Type 'T[P]' is not assignable to type 'U[P]'.
Type 'T[string]' is not assignable to type 'U[P]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
Type 'T[P]' is not assignable to type 'U[string]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
Type 'T[P]' is not assignable to type 'U[string]'.
Type 'T[string]' is not assignable to type 'U[string]'.
Type 'T' is not assignable to type 'U'.
==== tests/cases/conformance/types/mapped/mappedTypeRelationships.ts (27 errors) ====
@@ -115,10 +103,9 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(166,5): error TS
!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[keyof T]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
}
function f4<T, U extends T, K extends keyof T>(x: T, y: U, k: K) {
@@ -128,10 +115,9 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(166,5): error TS
!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[K]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
!!! error TS2322: Type 'T[K]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
!!! error TS2322: Type 'T[K]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
}
function f5<T, U extends T>(x: T, y: U, k: keyof U) {
@@ -143,10 +129,9 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(166,5): error TS
!!! error TS2322: Type 'T[keyof U]' is not assignable to type 'U[keyof U]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[keyof U]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
!!! error TS2322: Type 'T[keyof U]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
!!! error TS2322: Type 'T[keyof U]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
~~~~
!!! error TS2536: Type 'keyof U' cannot be used to index type 'T'.
}
@@ -160,10 +145,9 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(166,5): error TS
!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[K]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
!!! error TS2322: Type 'T[K]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
!!! error TS2322: Type 'T[K]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
~~~~
!!! error TS2536: Type 'K' cannot be used to index type 'T'.
}
@@ -197,15 +181,12 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(166,5): error TS
!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T] | undefined'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[keyof T] | undefined'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[keyof T]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[keyof T]'.
!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[keyof T]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[keyof T]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
!!! error TS2322: Type 'T[keyof T]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
}
function f13<T, U extends T, K extends keyof T>(x: T, y: Partial<U>, k: K) {
@@ -219,15 +200,12 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(166,5): error TS
!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K] | undefined'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[K] | undefined'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[K]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[K]'.
!!! error TS2322: Type 'T[K]' is not assignable to type 'U[K]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[K]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T[K]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
!!! error TS2322: Type 'T[K]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
}
function f20<T>(x: T, y: Readonly<T>, k: keyof T) {
@@ -342,10 +320,9 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(166,5): error TS
!!! error TS2322: Type 'T[P]' is not assignable to type 'U[P]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[P]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
!!! error TS2322: Type 'T[P]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
!!! error TS2322: Type 'T[P]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
}
function f72<T, U extends T>(x: { [P in keyof T]: T[P] }, y: { [P in keyof U]: U[P] }) {
@@ -388,9 +365,8 @@ tests/cases/conformance/types/mapped/mappedTypeRelationships.ts(166,5): error TS
!!! error TS2322: Type 'T[P]' is not assignable to type 'U[P]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[P]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
!!! error TS2322: Type 'T[P]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
!!! error TS2322: Type 'T[P]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T[string]' is not assignable to type 'U[string]'.
!!! error TS2322: Type 'T' is not assignable to type 'U'.
}

View File

@@ -44,10 +44,8 @@ tests/cases/compiler/promisePermutations.ts(133,19): error TS2345: Argument of t
tests/cases/compiler/promisePermutations.ts(134,19): error TS2345: Argument of type '<T>(x: T, cb: <U>(a: U) => U) => Promise<T>' is not assignable to parameter of type '(value: number) => IPromise<any>'.
tests/cases/compiler/promisePermutations.ts(137,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'IPromise<number>' is not a valid type argument because it is not a supertype of candidate 'IPromise<string>'.
Type 'string' is not assignable to type 'number'.
tests/cases/compiler/promisePermutations.ts(144,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'IPromise<number>' is not a valid type argument because it is not a supertype of candidate 'IPromise<string>'.
Type 'string' is not assignable to type 'number'.
tests/cases/compiler/promisePermutations.ts(152,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'Promise<number>' is not a valid type argument because it is not a supertype of candidate 'IPromise<string>'.
Types of property 'then' are incompatible.
@@ -61,7 +59,6 @@ tests/cases/compiler/promisePermutations.ts(156,21): error TS2345: Argument of t
Type 'number' is not assignable to type 'string'.
tests/cases/compiler/promisePermutations.ts(158,21): error TS2345: Argument of type '{ (x: number): IPromise<number>; (x: string): IPromise<string>; }' is not assignable to parameter of type '(value: number) => IPromise<string>'.
Type 'IPromise<number>' is not assignable to type 'IPromise<string>'.
Type 'number' is not assignable to type 'string'.
tests/cases/compiler/promisePermutations.ts(159,21): error TS2345: Argument of type '{ (x: number): Promise<number>; (x: string): Promise<string>; }' is not assignable to parameter of type '(value: number) => Promise<string>'.
Type 'Promise<number>' is not assignable to type 'Promise<string>'.
Type 'number' is not assignable to type 'string'.
@@ -286,7 +283,6 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t
~~~~~~~
!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
!!! error TS2453: Type argument candidate 'IPromise<number>' is not a valid type argument because it is not a supertype of candidate 'IPromise<string>'.
!!! error TS2453: Type 'string' is not assignable to type 'number'.
var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok
var r10 = testFunction10(x => x);
@@ -297,7 +293,6 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t
~~~~~~~~
!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
!!! error TS2453: Type argument candidate 'IPromise<number>' is not a valid type argument because it is not a supertype of candidate 'IPromise<string>'.
!!! error TS2453: Type 'string' is not assignable to type 'number'.
var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok
var s10 = testFunction10P(x => x);
var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok
@@ -328,7 +323,6 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t
~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '{ (x: number): IPromise<number>; (x: string): IPromise<string>; }' is not assignable to parameter of type '(value: number) => IPromise<string>'.
!!! error TS2345: Type 'IPromise<number>' is not assignable to type 'IPromise<string>'.
!!! error TS2345: Type 'number' is not assignable to type 'string'.
var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error
~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '{ (x: number): Promise<number>; (x: string): Promise<string>; }' is not assignable to parameter of type '(value: number) => Promise<string>'.

View File

@@ -44,10 +44,8 @@ tests/cases/compiler/promisePermutations2.ts(132,19): error TS2345: Argument of
tests/cases/compiler/promisePermutations2.ts(133,19): error TS2345: Argument of type '<T>(x: T, cb: <U>(a: U) => U) => Promise<T>' is not assignable to parameter of type '(value: number) => IPromise<any>'.
tests/cases/compiler/promisePermutations2.ts(136,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'IPromise<number>' is not a valid type argument because it is not a supertype of candidate 'IPromise<string>'.
Type 'string' is not assignable to type 'number'.
tests/cases/compiler/promisePermutations2.ts(143,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'IPromise<number>' is not a valid type argument because it is not a supertype of candidate 'IPromise<string>'.
Type 'string' is not assignable to type 'number'.
tests/cases/compiler/promisePermutations2.ts(151,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'Promise<number>' is not a valid type argument because it is not a supertype of candidate 'IPromise<string>'.
Types of property 'then' are incompatible.
@@ -61,7 +59,6 @@ tests/cases/compiler/promisePermutations2.ts(155,21): error TS2345: Argument of
Type 'number' is not assignable to type 'string'.
tests/cases/compiler/promisePermutations2.ts(157,21): error TS2345: Argument of type '{ (x: number): IPromise<number>; (x: string): IPromise<string>; }' is not assignable to parameter of type '(value: number) => IPromise<string>'.
Type 'IPromise<number>' is not assignable to type 'IPromise<string>'.
Type 'number' is not assignable to type 'string'.
tests/cases/compiler/promisePermutations2.ts(158,21): error TS2345: Argument of type '{ (x: number): Promise<number>; (x: string): Promise<string>; }' is not assignable to parameter of type '(value: number) => Promise<string>'.
Type 'Promise<number>' is not assignable to type 'Promise<string>'.
Type 'number' is not assignable to type 'string'.
@@ -285,7 +282,6 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of
~~~~~~~
!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
!!! error TS2453: Type argument candidate 'IPromise<number>' is not a valid type argument because it is not a supertype of candidate 'IPromise<string>'.
!!! error TS2453: Type 'string' is not assignable to type 'number'.
var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok
var r10 = testFunction10(x => x);
@@ -296,7 +292,6 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of
~~~~~~~~
!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
!!! error TS2453: Type argument candidate 'IPromise<number>' is not a valid type argument because it is not a supertype of candidate 'IPromise<string>'.
!!! error TS2453: Type 'string' is not assignable to type 'number'.
var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok
var s10 = testFunction10P(x => x);
var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok
@@ -327,7 +322,6 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of
~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '{ (x: number): IPromise<number>; (x: string): IPromise<string>; }' is not assignable to parameter of type '(value: number) => IPromise<string>'.
!!! error TS2345: Type 'IPromise<number>' is not assignable to type 'IPromise<string>'.
!!! error TS2345: Type 'number' is not assignable to type 'string'.
var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // ok
~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '{ (x: number): Promise<number>; (x: string): Promise<string>; }' is not assignable to parameter of type '(value: number) => Promise<string>'.

View File

@@ -47,10 +47,8 @@ tests/cases/compiler/promisePermutations3.ts(132,19): error TS2345: Argument of
tests/cases/compiler/promisePermutations3.ts(133,19): error TS2345: Argument of type '<T>(x: T, cb: <U>(a: U) => U) => Promise<T>' is not assignable to parameter of type '(value: number) => IPromise<any>'.
tests/cases/compiler/promisePermutations3.ts(136,11): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'IPromise<number>' is not a valid type argument because it is not a supertype of candidate 'IPromise<string>'.
Type 'string' is not assignable to type 'number'.
tests/cases/compiler/promisePermutations3.ts(143,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'IPromise<number>' is not a valid type argument because it is not a supertype of candidate 'IPromise<string>'.
Type 'string' is not assignable to type 'number'.
tests/cases/compiler/promisePermutations3.ts(151,12): error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
Type argument candidate 'Promise<number>' is not a valid type argument because it is not a supertype of candidate 'IPromise<string>'.
Types of property 'then' are incompatible.
@@ -64,7 +62,6 @@ tests/cases/compiler/promisePermutations3.ts(155,21): error TS2345: Argument of
Type 'number' is not assignable to type 'string'.
tests/cases/compiler/promisePermutations3.ts(157,21): error TS2345: Argument of type '{ (x: number): IPromise<number>; (x: string): IPromise<string>; }' is not assignable to parameter of type '(value: number) => IPromise<string>'.
Type 'IPromise<number>' is not assignable to type 'IPromise<string>'.
Type 'number' is not assignable to type 'string'.
tests/cases/compiler/promisePermutations3.ts(158,21): error TS2345: Argument of type '{ (x: number): Promise<number>; (x: string): Promise<string>; }' is not assignable to parameter of type '(value: number) => Promise<string>'.
Type 'Promise<number>' is not assignable to type 'Promise<string>'.
Type 'number' is not assignable to type 'string'.
@@ -297,7 +294,6 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of
~~~~~~~
!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
!!! error TS2453: Type argument candidate 'IPromise<number>' is not a valid type argument because it is not a supertype of candidate 'IPromise<string>'.
!!! error TS2453: Type 'string' is not assignable to type 'number'.
var s9g = s9.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok
var r10 = testFunction10(x => x);
@@ -308,7 +304,6 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of
~~~~~~~~
!!! error TS2453: The type argument for type parameter 'U' cannot be inferred from the usage. Consider specifying the type arguments explicitly.
!!! error TS2453: Type argument candidate 'IPromise<number>' is not a valid type argument because it is not a supertype of candidate 'IPromise<string>'.
!!! error TS2453: Type 'string' is not assignable to type 'number'.
var r10e = r10.then(testFunction, nIPromise, sIPromise).then(sIPromise, sIPromise, sIPromise); // ok
var s10 = testFunction10P(x => x);
var s10a = s10.then(testFunction10, testFunction10, testFunction10); // ok
@@ -339,7 +334,6 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of
~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '{ (x: number): IPromise<number>; (x: string): IPromise<string>; }' is not assignable to parameter of type '(value: number) => IPromise<string>'.
!!! error TS2345: Type 'IPromise<number>' is not assignable to type 'IPromise<string>'.
!!! error TS2345: Type 'number' is not assignable to type 'string'.
var s11b = s11.then(testFunction11P, testFunction11P, testFunction11P); // error
~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '{ (x: number): Promise<number>; (x: string): Promise<string>; }' is not assignable to parameter of type '(value: number) => Promise<string>'.

View File

@@ -0,0 +1,48 @@
tests/cases/compiler/recursiveTypeRelations.ts(8,5): error TS2391: Function implementation is missing or not immediately following the declaration.
tests/cases/compiler/recursiveTypeRelations.ts(27,38): error TS2304: Cannot find name 'ClassNameObject'.
tests/cases/compiler/recursiveTypeRelations.ts(27,61): error TS2304: Cannot find name 'ClassNameObject'.
==== tests/cases/compiler/recursiveTypeRelations.ts (3 errors) ====
// Repro from #14896
type Attributes<Keys extends string> = {
[Key in Keys]: string;
}
class Query<A extends Attributes<keyof A>> {
multiply<B extends Attributes<keyof B>>(x: B): Query<A & B>;
~~~~~~~~
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
}
// Repro from #14940
type ClassName<S> = keyof S;
type ClassNameMap<S> = { [K in keyof S]?: boolean }
type ClassNameObjectMap<S> = object & ClassNameMap<S>;
type ClassNameArg<S> = ClassName<S> | ClassNameObjectMap<S>;
export function css<S extends { [K in keyof S]: string }>(styles: S, ...classNames: ClassNameArg<S>[]): string {
const args = classNames.map(arg => {
if (arg == null) {
return null;
}
if (typeof arg == "string") {
return styles[arg];
}
if (typeof arg == "object") {
return Object.keys(arg).reduce<ClassNameObject>((obj: ClassNameObject, key: keyof S) => {
~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'ClassNameObject'.
~~~~~~~~~~~~~~~
!!! error TS2304: Cannot find name 'ClassNameObject'.
const exportedClassName = styles[key];
obj[exportedClassName] = (arg as ClassNameMap<S>)[key];
return obj;
}, {});
}
});
return "";
}

View File

@@ -0,0 +1,70 @@
//// [recursiveTypeRelations.ts]
// Repro from #14896
type Attributes<Keys extends string> = {
[Key in Keys]: string;
}
class Query<A extends Attributes<keyof A>> {
multiply<B extends Attributes<keyof B>>(x: B): Query<A & B>;
}
// Repro from #14940
type ClassName<S> = keyof S;
type ClassNameMap<S> = { [K in keyof S]?: boolean }
type ClassNameObjectMap<S> = object & ClassNameMap<S>;
type ClassNameArg<S> = ClassName<S> | ClassNameObjectMap<S>;
export function css<S extends { [K in keyof S]: string }>(styles: S, ...classNames: ClassNameArg<S>[]): string {
const args = classNames.map(arg => {
if (arg == null) {
return null;
}
if (typeof arg == "string") {
return styles[arg];
}
if (typeof arg == "object") {
return Object.keys(arg).reduce<ClassNameObject>((obj: ClassNameObject, key: keyof S) => {
const exportedClassName = styles[key];
obj[exportedClassName] = (arg as ClassNameMap<S>)[key];
return obj;
}, {});
}
});
return "";
}
//// [recursiveTypeRelations.js]
"use strict";
// Repro from #14896
exports.__esModule = true;
var Query = (function () {
function Query() {
}
return Query;
}());
function css(styles) {
var classNames = [];
for (var _i = 1; _i < arguments.length; _i++) {
classNames[_i - 1] = arguments[_i];
}
var args = classNames.map(function (arg) {
if (arg == null) {
return null;
}
if (typeof arg == "string") {
return styles[arg];
}
if (typeof arg == "object") {
return Object.keys(arg).reduce(function (obj, key) {
var exportedClassName = styles[key];
obj[exportedClassName] = arg[key];
return obj;
}, {});
}
});
return "";
}
exports.css = css;

View File

@@ -2,8 +2,6 @@ tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(5,19): error TS
Type 'string | number' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.
tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(6,19): error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'.
Type 'string | number' is not assignable to type 'number'.
Type 'string' is not assignable to type 'number'.
==== tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts (2 errors) ====
@@ -19,8 +17,6 @@ tests/cases/compiler/trailingCommaInHeterogenousArrayLiteral1.ts(6,19): error TS
this.test([1, 2, "hi", 5]);
~~~~~~~~~~~~~~~
!!! error TS2345: Argument of type '(string | number)[]' is not assignable to parameter of type 'number[]'.
!!! error TS2345: Type 'string | number' is not assignable to type 'number'.
!!! error TS2345: Type 'string' is not assignable to type 'number'.
}
}

View File

@@ -12,7 +12,6 @@ tests/cases/compiler/typeMatch2.ts(18,5): error TS2322: Type 'Animal[]' is not a
tests/cases/compiler/typeMatch2.ts(22,5): error TS2322: Type '{ f1: number; f2: Animal[]; }' is not assignable to type '{ f1: number; f2: Giraffe[]; }'.
Types of property 'f2' are incompatible.
Type 'Animal[]' is not assignable to type 'Giraffe[]'.
Type 'Animal' is not assignable to type 'Giraffe'.
tests/cases/compiler/typeMatch2.ts(34,26): error TS2322: Type '{ x: number; y: any; z: number; }' is not assignable to type '{ x: number; y: number; }'.
Object literal may only specify known properties, and 'z' does not exist in type '{ x: number; y: number; }'.
tests/cases/compiler/typeMatch2.ts(35,5): error TS2322: Type '{ x: number; }' is not assignable to type '{ x: number; y: number; }'.
@@ -62,7 +61,6 @@ tests/cases/compiler/typeMatch2.ts(35,5): error TS2322: Type '{ x: number; }' is
!!! error TS2322: Type '{ f1: number; f2: Animal[]; }' is not assignable to type '{ f1: number; f2: Giraffe[]; }'.
!!! error TS2322: Types of property 'f2' are incompatible.
!!! error TS2322: Type 'Animal[]' is not assignable to type 'Giraffe[]'.
!!! error TS2322: Type 'Animal' is not assignable to type 'Giraffe'.
}
function f4() {

View File

@@ -8,7 +8,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typePara
Type 'V' is not assignable to type 'T'.
Type 'Date' is not assignable to type 'T'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(26,5): error TS2322: Type 'V' is not assignable to type 'T'.
Type 'Date' is not assignable to type 'T'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(27,5): error TS2322: Type 'Date' is not assignable to type 'T'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(30,5): error TS2322: Type 'V' is not assignable to type 'U'.
Type 'Date' is not assignable to type 'U'.
@@ -18,7 +17,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typePara
Type 'V' is not assignable to type 'T'.
Type 'Date' is not assignable to type 'T'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(46,5): error TS2322: Type 'V' is not assignable to type 'T'.
Type 'Date' is not assignable to type 'T'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(47,5): error TS2322: Type 'Date' is not assignable to type 'T'.
tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typeParameterAssignability2.ts(50,5): error TS2322: Type 'V' is not assignable to type 'U'.
Type 'Date' is not assignable to type 'U'.
@@ -76,7 +74,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typePara
t = v; // error
~
!!! error TS2322: Type 'V' is not assignable to type 'T'.
!!! error TS2322: Type 'Date' is not assignable to type 'T'.
t = new Date(); // error
~
!!! error TS2322: Type 'Date' is not assignable to type 'T'.
@@ -112,7 +109,6 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/typePara
t = v; // error
~
!!! error TS2322: Type 'V' is not assignable to type 'T'.
!!! error TS2322: Type 'Date' is not assignable to type 'T'.
t = new Date(); // error
~
!!! error TS2322: Type 'Date' is not assignable to type 'T'.

View File

@@ -7,7 +7,6 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(
Type 'string' is not assignable to type 'number'.
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(13,7): error TS2322: Type '() => AsyncIterableIterator<"a">' is not assignable to type '() => AsyncIterableIterator<number>'.
Type 'AsyncIterableIterator<"a">' is not assignable to type 'AsyncIterableIterator<number>'.
Type '"a"' is not assignable to type 'number'.
tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(16,7): error TS2322: Type '() => AsyncIterableIterator<"a">' is not assignable to type '() => AsyncIterable<number>'.
Type 'AsyncIterableIterator<"a">' is not assignable to type 'AsyncIterable<number>'.
Types of property '[Symbol.asyncIterator]' are incompatible.
@@ -84,7 +83,6 @@ tests/cases/conformance/types/asyncGenerators/types.asyncGenerators.esnext.2.ts(
~~~~~~~~~~~~~~
!!! error TS2322: Type '() => AsyncIterableIterator<"a">' is not assignable to type '() => AsyncIterableIterator<number>'.
!!! error TS2322: Type 'AsyncIterableIterator<"a">' is not assignable to type 'AsyncIterableIterator<number>'.
!!! error TS2322: Type '"a"' is not assignable to type 'number'.
yield* (async function * () { yield "a"; })();
};
const assignability4: () => AsyncIterable<number> = async function * () {

View File

@@ -0,0 +1,35 @@
// Repro from #14896
type Attributes<Keys extends string> = {
[Key in Keys]: string;
}
class Query<A extends Attributes<keyof A>> {
multiply<B extends Attributes<keyof B>>(x: B): Query<A & B>;
}
// Repro from #14940
type ClassName<S> = keyof S;
type ClassNameMap<S> = { [K in keyof S]?: boolean }
type ClassNameObjectMap<S> = object & ClassNameMap<S>;
type ClassNameArg<S> = ClassName<S> | ClassNameObjectMap<S>;
export function css<S extends { [K in keyof S]: string }>(styles: S, ...classNames: ClassNameArg<S>[]): string {
const args = classNames.map(arg => {
if (arg == null) {
return null;
}
if (typeof arg == "string") {
return styles[arg];
}
if (typeof arg == "object") {
return Object.keys(arg).reduce<ClassNameObject>((obj: ClassNameObject, key: keyof S) => {
const exportedClassName = styles[key];
obj[exportedClassName] = (arg as ClassNameMap<S>)[key];
return obj;
}, {});
}
});
return "";
}