diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index da1af15dfa458..3b736093e78e4 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8691,10 +8691,7 @@ namespace ts { const len = typeSet.length; const index = len && type.id > typeSet[len - 1].id ? ~len : binarySearch(typeSet, type, getTypeId, compareValues); if (index < 0) { - if (!(flags & TypeFlags.Object && (type).objectFlags & ObjectFlags.Anonymous && - type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method) && containsIdenticalType(typeSet, type))) { - typeSet.splice(~index, 0, type); - } + typeSet.splice(~index, 0, type); } } } @@ -8710,15 +8707,6 @@ namespace ts { return includes; } - function containsIdenticalType(types: ReadonlyArray, type: Type) { - for (const t of types) { - if (isTypeIdenticalTo(t, type)) { - return true; - } - } - return false; - } - function isSubtypeOfAny(source: Type, targets: ReadonlyArray): boolean { for (const target of targets) { if (source !== target && isTypeSubtypeOf(source, target) && ( @@ -8899,10 +8887,7 @@ namespace ts { if (flags & TypeFlags.AnyOrUnknown) { if (type === wildcardType) includes |= TypeFlags.Wildcard; } - else if ((strictNullChecks || !(flags & TypeFlags.Nullable)) && !contains(typeSet, type) && - !(flags & TypeFlags.Object && (type).objectFlags & ObjectFlags.Anonymous && - type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method) && - containsIdenticalType(typeSet, type))) { + else if ((strictNullChecks || !(flags & TypeFlags.Nullable)) && !contains(typeSet, type)) { typeSet.push(type); } } diff --git a/tests/baselines/reference/checkJsxChildrenProperty4.errors.txt b/tests/baselines/reference/checkJsxChildrenProperty4.errors.txt index 4851bc3b4669e..8e7a3adb51845 100644 --- a/tests/baselines/reference/checkJsxChildrenProperty4.errors.txt +++ b/tests/baselines/reference/checkJsxChildrenProperty4.errors.txt @@ -1,8 +1,8 @@ tests/cases/conformance/jsx/file.tsx(24,28): error TS2551: Property 'NAme' does not exist on type 'IUser'. Did you mean 'Name'? -tests/cases/conformance/jsx/file.tsx(32,10): error TS2322: Type '{ children: ((user: IUser) => Element)[]; }' is not assignable to type 'IFetchUserProps'. +tests/cases/conformance/jsx/file.tsx(32,10): error TS2322: Type '{ children: (((user: IUser) => Element) | ((user: IUser) => Element))[]; }' is not assignable to type 'IFetchUserProps'. Types of property 'children' are incompatible. - Type '((user: IUser) => Element)[]' is not assignable to type '(user: IUser) => Element'. - Type '((user: IUser) => Element)[]' provides no match for the signature '(user: IUser): Element'. + Type '(((user: IUser) => Element) | ((user: IUser) => Element))[]' is not assignable to type '(user: IUser) => Element'. + Type '(((user: IUser) => Element) | ((user: IUser) => Element))[]' provides no match for the signature '(user: IUser): Element'. ==== tests/cases/conformance/jsx/file.tsx (2 errors) ==== @@ -42,10 +42,10 @@ tests/cases/conformance/jsx/file.tsx(32,10): error TS2322: Type '{ children: ((u return ( ~~~~~~~~~ -!!! error TS2322: Type '{ children: ((user: IUser) => Element)[]; }' is not assignable to type 'IFetchUserProps'. +!!! error TS2322: Type '{ children: (((user: IUser) => Element) | ((user: IUser) => Element))[]; }' is not assignable to type 'IFetchUserProps'. !!! error TS2322: Types of property 'children' are incompatible. -!!! error TS2322: Type '((user: IUser) => Element)[]' is not assignable to type '(user: IUser) => Element'. -!!! error TS2322: Type '((user: IUser) => Element)[]' provides no match for the signature '(user: IUser): Element'. +!!! error TS2322: Type '(((user: IUser) => Element) | ((user: IUser) => Element))[]' is not assignable to type '(user: IUser) => Element'. +!!! error TS2322: Type '(((user: IUser) => Element) | ((user: IUser) => Element))[]' provides no match for the signature '(user: IUser): Element'. diff --git a/tests/baselines/reference/overrideBaseIntersectionMethod.types b/tests/baselines/reference/overrideBaseIntersectionMethod.types index 57d06fe648f45..3ca80a06a1a78 100644 --- a/tests/baselines/reference/overrideBaseIntersectionMethod.types +++ b/tests/baselines/reference/overrideBaseIntersectionMethod.types @@ -78,9 +78,9 @@ class Foo extends WithLocation(Point) { return super.getLocation() >super.getLocation() : [number, number] ->super.getLocation : () => [number, number] +>super.getLocation : (() => [number, number]) & (() => [number, number]) >super : WithLocation.(Anonymous class) & Point ->getLocation : () => [number, number] +>getLocation : (() => [number, number]) & (() => [number, number]) } whereAmI() { >whereAmI : () => [number, number] diff --git a/tests/baselines/reference/typeParameterExtendingUnion1.types b/tests/baselines/reference/typeParameterExtendingUnion1.types index 85c2096823ba1..e3eb4c14ca032 100644 --- a/tests/baselines/reference/typeParameterExtendingUnion1.types +++ b/tests/baselines/reference/typeParameterExtendingUnion1.types @@ -30,9 +30,9 @@ function f(a: T) { a.run(); >a.run() : void ->a.run : () => void +>a.run : (() => void) | (() => void) >a : T ->run : () => void +>run : (() => void) | (() => void) run(a); >run(a) : void diff --git a/tests/baselines/reference/typeParameterExtendingUnion2.types b/tests/baselines/reference/typeParameterExtendingUnion2.types index c19076ddd680d..074ac3b3fff21 100644 --- a/tests/baselines/reference/typeParameterExtendingUnion2.types +++ b/tests/baselines/reference/typeParameterExtendingUnion2.types @@ -19,9 +19,9 @@ function run(a: Cat | Dog) { a.run(); >a.run() : void ->a.run : () => void +>a.run : (() => void) | (() => void) >a : Cat | Dog ->run : () => void +>run : (() => void) | (() => void) } function f(a: T) { @@ -30,9 +30,9 @@ function f(a: T) { a.run(); >a.run() : void ->a.run : () => void +>a.run : (() => void) | (() => void) >a : T ->run : () => void +>run : (() => void) | (() => void) run(a); >run(a) : void diff --git a/tests/baselines/reference/unionTypeMembers.types b/tests/baselines/reference/unionTypeMembers.types index 5b19ab5540c49..e26d00c45f96a 100644 --- a/tests/baselines/reference/unionTypeMembers.types +++ b/tests/baselines/reference/unionTypeMembers.types @@ -95,9 +95,9 @@ str = x.commonMethodType(str); // (a: string) => string so result should be stri >str = x.commonMethodType(str) : string >str : string >x.commonMethodType(str) : string ->x.commonMethodType : (a: string) => string +>x.commonMethodType : ((a: string) => string) | ((a: string) => string) >x : I1 | I2 ->commonMethodType : (a: string) => string +>commonMethodType : ((a: string) => string) | ((a: string) => string) >str : string strOrNum = x.commonPropertyDifferenType; @@ -133,36 +133,36 @@ num = x.commonMethodWithTypeParameter(num); >num = x.commonMethodWithTypeParameter(num) : number >num : number >x.commonMethodWithTypeParameter(num) : number ->x.commonMethodWithTypeParameter : (a: number) => number +>x.commonMethodWithTypeParameter : ((a: number) => number) | ((a: number) => number) >x : I1 | I2 ->commonMethodWithTypeParameter : (a: number) => number +>commonMethodWithTypeParameter : ((a: number) => number) | ((a: number) => number) >num : number num = x.commonMethodWithOwnTypeParameter(num); >num = x.commonMethodWithOwnTypeParameter(num) : number >num : number >x.commonMethodWithOwnTypeParameter(num) : number ->x.commonMethodWithOwnTypeParameter : (a: U) => U +>x.commonMethodWithOwnTypeParameter : ((a: U) => U) | ((a: U) => U) >x : I1 | I2 ->commonMethodWithOwnTypeParameter : (a: U) => U +>commonMethodWithOwnTypeParameter : ((a: U) => U) | ((a: U) => U) >num : number str = x.commonMethodWithOwnTypeParameter(str); >str = x.commonMethodWithOwnTypeParameter(str) : string >str : string >x.commonMethodWithOwnTypeParameter(str) : string ->x.commonMethodWithOwnTypeParameter : (a: U) => U +>x.commonMethodWithOwnTypeParameter : ((a: U) => U) | ((a: U) => U) >x : I1 | I2 ->commonMethodWithOwnTypeParameter : (a: U) => U +>commonMethodWithOwnTypeParameter : ((a: U) => U) | ((a: U) => U) >str : string strOrNum = x.commonMethodWithOwnTypeParameter(strOrNum); >strOrNum = x.commonMethodWithOwnTypeParameter(strOrNum) : string | number >strOrNum : string | number >x.commonMethodWithOwnTypeParameter(strOrNum) : string | number ->x.commonMethodWithOwnTypeParameter : (a: U) => U +>x.commonMethodWithOwnTypeParameter : ((a: U) => U) | ((a: U) => U) >x : I1 | I2 ->commonMethodWithOwnTypeParameter : (a: U) => U +>commonMethodWithOwnTypeParameter : ((a: U) => U) | ((a: U) => U) >strOrNum : string | number x.propertyOnlyInI1; // error