diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0991030bff6cc..8e95c8b3bfc3e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -22914,7 +22914,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // of the much more expensive N * M comparison matrix we explore below. We erase type parameters // as they are known to always be the same. for (let i = 0; i < targetSignatures.length; i++) { - const related = signatureRelatedTo(sourceSignatures[i], targetSignatures[i], /*erase*/ true, reportErrors, intersectionState, incompatibleReporter(sourceSignatures[i], targetSignatures[i])); + const related = signatureRelatedTo(sourceSignatures[i], targetSignatures[i], /*erase*/ !inVarianceComputation, reportErrors, intersectionState, incompatibleReporter(sourceSignatures[i], targetSignatures[i])); if (!related) { return Ternary.False; } diff --git a/src/compiler/corePublic.ts b/src/compiler/corePublic.ts index c026d2c741f79..9020af6f7b300 100644 --- a/src/compiler/corePublic.ts +++ b/src/compiler/corePublic.ts @@ -15,11 +15,11 @@ export interface MapLike { [index: string]: T; } -export interface SortedReadonlyArray extends ReadonlyArray { +export interface SortedReadonlyArray extends ReadonlyArray { " __sortedArrayBrand": any; } -export interface SortedArray extends Array { +export interface SortedArray extends Array { " __sortedArrayBrand": any; } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 1f796f8b2a0da..f8b836fff36d5 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1535,12 +1535,12 @@ export type HasContainerFlags = | IsObjectLiteralOrClassExpressionMethodOrAccessor; /** @internal */ -export interface MutableNodeArray extends Array, TextRange { +export interface MutableNodeArray extends Array, TextRange { hasTrailingComma: boolean; /** @internal */ transformFlags: TransformFlags; // Flags for transforms, possibly undefined } -export interface NodeArray extends ReadonlyArray, ReadonlyTextRange { +export interface NodeArray extends ReadonlyArray, ReadonlyTextRange { readonly hasTrailingComma: boolean; /** @internal */ transformFlags: TransformFlags; // Flags for transforms, possibly undefined } diff --git a/tests/baselines/reference/api/typescript.d.ts b/tests/baselines/reference/api/typescript.d.ts index 4cd20ac817878..c23ba55b3902c 100644 --- a/tests/baselines/reference/api/typescript.d.ts +++ b/tests/baselines/reference/api/typescript.d.ts @@ -4145,10 +4145,10 @@ declare namespace ts { interface MapLike { [index: string]: T; } - interface SortedReadonlyArray extends ReadonlyArray { + interface SortedReadonlyArray extends ReadonlyArray { " __sortedArrayBrand": any; } - interface SortedArray extends Array { + interface SortedArray extends Array { " __sortedArrayBrand": any; } type Path = string & { @@ -4889,7 +4889,7 @@ declare namespace ts { type HasExpressionInitializer = VariableDeclaration | ParameterDeclaration | BindingElement | PropertyDeclaration | PropertyAssignment | EnumMember; type HasDecorators = ParameterDeclaration | PropertyDeclaration | MethodDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | ClassExpression | ClassDeclaration; type HasModifiers = TypeParameterDeclaration | ParameterDeclaration | ConstructorTypeNode | PropertySignature | PropertyDeclaration | MethodSignature | MethodDeclaration | ConstructorDeclaration | GetAccessorDeclaration | SetAccessorDeclaration | IndexSignatureDeclaration | FunctionExpression | ArrowFunction | ClassExpression | VariableStatement | FunctionDeclaration | ClassDeclaration | InterfaceDeclaration | TypeAliasDeclaration | EnumDeclaration | ModuleDeclaration | ImportEqualsDeclaration | ImportDeclaration | ExportAssignment | ExportDeclaration; - interface NodeArray extends ReadonlyArray, ReadonlyTextRange { + interface NodeArray extends ReadonlyArray, ReadonlyTextRange { readonly hasTrailingComma: boolean; } interface Token extends Node { diff --git a/tests/baselines/reference/complexRecursiveCollections.errors.txt b/tests/baselines/reference/complexRecursiveCollections.errors.txt index 3f51359243a8f..020147b964bd7 100644 --- a/tests/baselines/reference/complexRecursiveCollections.errors.txt +++ b/tests/baselines/reference/complexRecursiveCollections.errors.txt @@ -1,3 +1,11 @@ +immutable.ts(305,22): error TS2430: Interface 'Set' incorrectly extends interface 'Seq'. + The types of 'map(...).filter(...).concat(...).toMap().toSeq().toOrderedMap().keySeq().toMap().mapKeys(...).toSeq().toOrderedMap().toSet().union' are incompatible between these types. + Type '(...collections: (never[] | Collection)[]) => Set' is not assignable to type '(...collections: (any[] | Collection)[]) => Set'. + Types of parameters 'collections' and 'collections' are incompatible. + Type 'any[] | Collection' is not assignable to type 'never[] | Collection'. + Type 'any[]' is not assignable to type 'never[] | Collection'. + Type 'any[]' is not assignable to type 'never[]'. + Type 'any' is not assignable to type 'never'. immutable.ts(341,22): error TS2430: Interface 'Keyed' incorrectly extends interface 'Collection'. The types returned by 'toSeq()' are incompatible between these types. Type 'Keyed' is not assignable to type 'this'. @@ -33,7 +41,7 @@ immutable.ts(391,22): error TS2430: Interface 'Set' incorrectly extends inter flatMap(mapper: (value: T, key: void, iter: this) => Ara, context?: any): N2; toSeq(): N2; } -==== immutable.ts (3 errors) ==== +==== immutable.ts (4 errors) ==== // Test that complex recursive collections can pass the `extends` assignability check without // running out of memory. This bug was exposed in Typescript 2.4 when more generic signatures // started being checked. @@ -339,6 +347,15 @@ immutable.ts(391,22): error TS2430: Interface 'Set' incorrectly extends inter export function Set(): Seq.Set; export function Set(collection: Iterable): Seq.Set; export interface Set extends Seq, Collection.Set { + ~~~ +!!! error TS2430: Interface 'Set' incorrectly extends interface 'Seq'. +!!! error TS2430: The types of 'map(...).filter(...).concat(...).toMap().toSeq().toOrderedMap().keySeq().toMap().mapKeys(...).toSeq().toOrderedMap().toSet().union' are incompatible between these types. +!!! error TS2430: Type '(...collections: (never[] | Collection)[]) => Set' is not assignable to type '(...collections: (any[] | Collection)[]) => Set'. +!!! error TS2430: Types of parameters 'collections' and 'collections' are incompatible. +!!! error TS2430: Type 'any[] | Collection' is not assignable to type 'never[] | Collection'. +!!! error TS2430: Type 'any[]' is not assignable to type 'never[] | Collection'. +!!! error TS2430: Type 'any[]' is not assignable to type 'never[]'. +!!! error TS2430: Type 'any' is not assignable to type 'never'. toJS(): Array; toJSON(): Array; toSeq(): this; diff --git a/tests/baselines/reference/complexRecursiveCollections.types b/tests/baselines/reference/complexRecursiveCollections.types index 0aa394d46b370..2a6a5c12d81a7 100644 --- a/tests/baselines/reference/complexRecursiveCollections.types +++ b/tests/baselines/reference/complexRecursiveCollections.types @@ -1139,7 +1139,7 @@ declare module Immutable { >Seq : typeof Seq function isSeq(maybeSeq: any): maybeSeq is Seq.Indexed | Seq.Keyed; ->isSeq : (maybeSeq: any) => maybeSeq is Indexed | Keyed +>isSeq : (maybeSeq: any) => maybeSeq is Keyed | Indexed >maybeSeq : any >Seq : any >Seq : any diff --git a/tests/baselines/reference/conditionalTypes2.errors.txt b/tests/baselines/reference/conditionalTypes2.errors.txt index ef0eab5c43e39..b6923c597cf65 100644 --- a/tests/baselines/reference/conditionalTypes2.errors.txt +++ b/tests/baselines/reference/conditionalTypes2.errors.txt @@ -33,9 +33,16 @@ conditionalTypes2.ts(74,12): error TS2345: Argument of type 'Extract' is not assignable to parameter of type '{ foo: string; bat: string; }'. Type 'T extends Bar ? T : never' is not assignable to type '{ foo: string; bat: string; }'. Property 'bat' is missing in type 'Bar & Foo' but required in type '{ foo: string; bat: string; }'. +conditionalTypes2.ts(91,5): error TS2416: Property 'tail' in type 'Vector' is not assignable to the same property in base type 'Seq'. + Type '() => Opt>' is not assignable to type '() => Opt>'. + Call signature return types 'Opt>' and 'Opt>' are incompatible. + The types returned by 'toVector().tail().toVector()' are incompatible between these types. + Type 'Vector>>' is not assignable to type 'Vector>>'. + Type 'Vector>' is not assignable to type 'Vector>'. +conditionalTypes2.ts(94,5): error TS2394: This overload signature is not compatible with its implementation signature. -==== conditionalTypes2.ts (7 errors) ==== +==== conditionalTypes2.ts (9 errors) ==== interface Covariant { foo: T extends string ? T : number; } @@ -177,9 +184,19 @@ conditionalTypes2.ts(75,12): error TS2345: Argument of type 'Extract2 implements Seq { tail(): Opt> { + ~~~~ +!!! error TS2416: Property 'tail' in type 'Vector' is not assignable to the same property in base type 'Seq'. +!!! error TS2416: Type '() => Opt>' is not assignable to type '() => Opt>'. +!!! error TS2416: Call signature return types 'Opt>' and 'Opt>' are incompatible. +!!! error TS2416: The types returned by 'toVector().tail().toVector()' are incompatible between these types. +!!! error TS2416: Type 'Vector>>' is not assignable to type 'Vector>>'. +!!! error TS2416: Type 'Vector>' is not assignable to type 'Vector>'. return undefined; } partition2(predicate:(v:T)=>v is U): [Vector,Vector>]; + ~~~~~~~~~~ +!!! error TS2394: This overload signature is not compatible with its implementation signature. +!!! related TS2750 conditionalTypes2.ts:96:5: The implementation signature is declared here. partition2(predicate:(x:T)=>boolean): [Vector,Vector]; partition2(predicate:(v:T)=>boolean): [Vector,Vector] { return undefined; diff --git a/tests/baselines/reference/genericSignaturesConstrainedToDifferingGenericsNotCompatible.errors.txt b/tests/baselines/reference/genericSignaturesConstrainedToDifferingGenericsNotCompatible.errors.txt new file mode 100644 index 0000000000000..625a942321cb1 --- /dev/null +++ b/tests/baselines/reference/genericSignaturesConstrainedToDifferingGenericsNotCompatible.errors.txt @@ -0,0 +1,74 @@ +genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts(9,5): error TS2322: Type 'Fn' is not assignable to type 'Fn'. + Type 'T1' is not assignable to type 'T2'. + 'T2' could be instantiated with an arbitrary type which could be unrelated to 'T1'. +genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts(10,5): error TS2322: Type 'Fn' is not assignable to type 'Fn'. + Type 'T2' is not assignable to type 'T1'. + 'T1' could be instantiated with an arbitrary type which could be unrelated to 'T2'. +genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts(12,5): error TS2322: Type 'Concrete2' is not assignable to type 'Concrete1'. + Types of parameters 'x' and 'x' are incompatible. + Type 'U' is not assignable to type 'string'. + Type 'number' is not assignable to type 'string'. +genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts(13,5): error TS2322: Type 'Concrete1' is not assignable to type 'Concrete2'. + Types of parameters 'x' and 'x' are incompatible. + Type 'U' is not assignable to type 'number'. + Type 'string' is not assignable to type 'number'. +genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts(15,5): error TS2322: Type 'Concrete1' is not assignable to type 'Fn'. + Types of parameters 'x' and 'x' are incompatible. + Type 'U' is not assignable to type 'number'. + Type 'T1' is not assignable to type 'number'. +genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts(16,5): error TS2322: Type 'Fn' is not assignable to type 'Concrete1'. + Types of parameters 'x' and 'x' are incompatible. + Type 'U' is not assignable to type 'T1'. + 'T1' could be instantiated with an arbitrary type which could be unrelated to 'U'. + + +==== genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts (6 errors) ==== + type Fn = (x: U) => U; + + type Concrete1 = (x: U) => U; + type Concrete2 = (x: U) => U; + + function f(t1: Fn, t2: Fn, c1: Concrete1, c2: Concrete2) { + // every single one of these assignments should error + + t1 = t2; + ~~ +!!! error TS2322: Type 'Fn' is not assignable to type 'Fn'. +!!! error TS2322: Type 'T1' is not assignable to type 'T2'. +!!! error TS2322: 'T2' could be instantiated with an arbitrary type which could be unrelated to 'T1'. +!!! related TS2208 genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts:6:12: This type parameter might need an `extends T2` constraint. + t2 = t1; + ~~ +!!! error TS2322: Type 'Fn' is not assignable to type 'Fn'. +!!! error TS2322: Type 'T2' is not assignable to type 'T1'. +!!! error TS2322: 'T1' could be instantiated with an arbitrary type which could be unrelated to 'T2'. +!!! related TS2208 genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts:6:16: This type parameter might need an `extends T1` constraint. + + c1 = c2; + ~~ +!!! error TS2322: Type 'Concrete2' is not assignable to type 'Concrete1'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'U' is not assignable to type 'string'. +!!! error TS2322: Type 'number' is not assignable to type 'string'. + c2 = c1; + ~~ +!!! error TS2322: Type 'Concrete1' is not assignable to type 'Concrete2'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'U' is not assignable to type 'number'. +!!! error TS2322: Type 'string' is not assignable to type 'number'. + + t1 = c1; + ~~ +!!! error TS2322: Type 'Concrete1' is not assignable to type 'Fn'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'U' is not assignable to type 'number'. +!!! error TS2322: Type 'T1' is not assignable to type 'number'. +!!! related TS2208 genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts:6:12: This type parameter might need an `extends number` constraint. + c1 = t1; + ~~ +!!! error TS2322: Type 'Fn' is not assignable to type 'Concrete1'. +!!! error TS2322: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2322: Type 'U' is not assignable to type 'T1'. +!!! error TS2322: 'T1' could be instantiated with an arbitrary type which could be unrelated to 'U'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/genericSignaturesConstrainedToDifferingGenericsNotCompatible.js b/tests/baselines/reference/genericSignaturesConstrainedToDifferingGenericsNotCompatible.js new file mode 100644 index 0000000000000..4b5a028f79506 --- /dev/null +++ b/tests/baselines/reference/genericSignaturesConstrainedToDifferingGenericsNotCompatible.js @@ -0,0 +1,33 @@ +//// [tests/cases/compiler/genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts] //// + +//// [genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts] +type Fn = (x: U) => U; + +type Concrete1 = (x: U) => U; +type Concrete2 = (x: U) => U; + +function f(t1: Fn, t2: Fn, c1: Concrete1, c2: Concrete2) { + // every single one of these assignments should error + + t1 = t2; + t2 = t1; + + c1 = c2; + c2 = c1; + + t1 = c1; + c1 = t1; +} + + +//// [genericSignaturesConstrainedToDifferingGenericsNotCompatible.js] +"use strict"; +function f(t1, t2, c1, c2) { + // every single one of these assignments should error + t1 = t2; + t2 = t1; + c1 = c2; + c2 = c1; + t1 = c1; + c1 = t1; +} diff --git a/tests/baselines/reference/genericSignaturesConstrainedToDifferingGenericsNotCompatible.symbols b/tests/baselines/reference/genericSignaturesConstrainedToDifferingGenericsNotCompatible.symbols new file mode 100644 index 0000000000000..f7b53cd99f5ff --- /dev/null +++ b/tests/baselines/reference/genericSignaturesConstrainedToDifferingGenericsNotCompatible.symbols @@ -0,0 +1,68 @@ +//// [tests/cases/compiler/genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts] //// + +=== genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts === +type Fn = (x: U) => U; +>Fn : Symbol(Fn, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 0)) +>T : Symbol(T, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 8)) +>U : Symbol(U, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 14)) +>T : Symbol(T, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 8)) +>x : Symbol(x, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 27)) +>U : Symbol(U, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 14)) +>U : Symbol(U, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 14)) + +type Concrete1 = (x: U) => U; +>Concrete1 : Symbol(Concrete1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 38)) +>U : Symbol(U, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 2, 18)) +>x : Symbol(x, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 2, 36)) +>U : Symbol(U, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 2, 18)) +>U : Symbol(U, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 2, 18)) + +type Concrete2 = (x: U) => U; +>Concrete2 : Symbol(Concrete2, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 2, 47)) +>U : Symbol(U, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 3, 18)) +>x : Symbol(x, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 3, 36)) +>U : Symbol(U, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 3, 18)) +>U : Symbol(U, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 3, 18)) + +function f(t1: Fn, t2: Fn, c1: Concrete1, c2: Concrete2) { +>f : Symbol(f, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 3, 47)) +>T1 : Symbol(T1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 11)) +>T2 : Symbol(T2, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 14)) +>t1 : Symbol(t1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 19)) +>Fn : Symbol(Fn, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 0)) +>T1 : Symbol(T1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 11)) +>t2 : Symbol(t2, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 30)) +>Fn : Symbol(Fn, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 0)) +>T2 : Symbol(T2, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 14)) +>c1 : Symbol(c1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 42)) +>Concrete1 : Symbol(Concrete1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 0, 38)) +>c2 : Symbol(c2, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 57)) +>Concrete2 : Symbol(Concrete2, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 2, 47)) + + // every single one of these assignments should error + + t1 = t2; +>t1 : Symbol(t1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 19)) +>t2 : Symbol(t2, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 30)) + + t2 = t1; +>t2 : Symbol(t2, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 30)) +>t1 : Symbol(t1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 19)) + + c1 = c2; +>c1 : Symbol(c1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 42)) +>c2 : Symbol(c2, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 57)) + + c2 = c1; +>c2 : Symbol(c2, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 57)) +>c1 : Symbol(c1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 42)) + + t1 = c1; +>t1 : Symbol(t1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 19)) +>c1 : Symbol(c1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 42)) + + c1 = t1; +>c1 : Symbol(c1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 42)) +>t1 : Symbol(t1, Decl(genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts, 5, 19)) +} + diff --git a/tests/baselines/reference/genericSignaturesConstrainedToDifferingGenericsNotCompatible.types b/tests/baselines/reference/genericSignaturesConstrainedToDifferingGenericsNotCompatible.types new file mode 100644 index 0000000000000..ff1623d9bd842 --- /dev/null +++ b/tests/baselines/reference/genericSignaturesConstrainedToDifferingGenericsNotCompatible.types @@ -0,0 +1,55 @@ +//// [tests/cases/compiler/genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts] //// + +=== genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts === +type Fn = (x: U) => U; +>Fn : Fn +>x : U + +type Concrete1 = (x: U) => U; +>Concrete1 : (x: U) => U +>x : U + +type Concrete2 = (x: U) => U; +>Concrete2 : (x: U) => U +>x : U + +function f(t1: Fn, t2: Fn, c1: Concrete1, c2: Concrete2) { +>f : (t1: Fn, t2: Fn, c1: Concrete1, c2: Concrete2) => void +>t1 : Fn +>t2 : Fn +>c1 : Concrete1 +>c2 : Concrete2 + + // every single one of these assignments should error + + t1 = t2; +>t1 = t2 : Fn +>t1 : Fn +>t2 : Fn + + t2 = t1; +>t2 = t1 : Fn +>t2 : Fn +>t1 : Fn + + c1 = c2; +>c1 = c2 : Concrete2 +>c1 : Concrete1 +>c2 : Concrete2 + + c2 = c1; +>c2 = c1 : Concrete1 +>c2 : Concrete2 +>c1 : Concrete1 + + t1 = c1; +>t1 = c1 : Concrete1 +>t1 : Fn +>c1 : Concrete1 + + c1 = t1; +>c1 = t1 : Fn +>c1 : Concrete1 +>t1 : Fn +} + diff --git a/tests/baselines/reference/styledComponentsInstantiaionLimitNotReached.errors.txt b/tests/baselines/reference/styledComponentsInstantiaionLimitNotReached.errors.txt new file mode 100644 index 0000000000000..2d5c3c0d0545b --- /dev/null +++ b/tests/baselines/reference/styledComponentsInstantiaionLimitNotReached.errors.txt @@ -0,0 +1,207 @@ +styledComponentsInstantiaionLimitNotReached.ts(171,8): error TS2615: Type of property 'propTypes' circularly references itself in mapped type 'ForwardRefExoticBase & Partial>, "theme"> & { theme?: any; } & WithChildrenIfReactComponentClass>>'. + + +==== styledComponentsInstantiaionLimitNotReached.ts (1 errors) ==== + /// + import * as React from "react"; + + interface REACT_STATICS { + childContextTypes: true; + contextType: true; + contextTypes: true; + defaultProps: true; + displayName: true; + getDefaultProps: true; + getDerivedStateFromError: true; + getDerivedStateFromProps: true; + mixins: true; + propTypes: true; + type: true; + } + + interface KNOWN_STATICS { + name: true; + length: true; + prototype: true; + caller: true; + callee: true; + arguments: true; + arity: true; + } + + interface MEMO_STATICS { + '$$typeof': true; + compare: true; + defaultProps: true; + displayName: true; + propTypes: true; + type: true; + } + + interface FORWARD_REF_STATICS { + '$$typeof': true; + render: true; + defaultProps: true; + displayName: true; + propTypes: true; + } + + + type NonReactStatics< + S extends React.ComponentType, + C extends { + [key: string]: true + } = {} + > = { + [key in Exclude< + keyof S, + S extends React.MemoExoticComponent + ? keyof MEMO_STATICS | keyof C + : S extends React.ForwardRefExoticComponent + ? keyof FORWARD_REF_STATICS | keyof C + : keyof REACT_STATICS | keyof KNOWN_STATICS | keyof C + >]: S[key] + }; + + export type AnyStyledComponent = StyledComponent | StyledComponent; + export type StyledComponent< + C extends keyof JSX.IntrinsicElements | React.ComponentType, + T extends object, + O extends object = {}, + A extends keyof any = never + > = // the "string" allows this to be used as an object key + // I really want to avoid this if possible but it's the only way to use nesting with object styles... + string & + StyledComponentBase & + NonReactStatics ? C : never>; + + export type StyledComponentProps< + // The Component from whose props are derived + C extends string | React.ComponentType, + // The Theme from the current context + T extends object, + // The other props added by the template + O extends object, + // The props that are made optional by .attrs + A extends keyof any + > = + // Distribute O if O is a union type + O extends object + ? WithOptionalTheme< + Omit< + ReactDefaultizedProps< + C, + React.ComponentPropsWithRef< + C extends IntrinsicElementsKeys | React.ComponentType ? C : never + > + > & + O, + A + > & + Partial< + Pick< + React.ComponentPropsWithRef< + C extends IntrinsicElementsKeys | React.ComponentType ? C : never + > & + O, + A + > + >, + T + > & + WithChildrenIfReactComponentClass + : never; + + type Defaultize = P extends any + ? string extends keyof P + ? P + : Pick> & + Partial>> & + Partial>> + : never; + + type ReactDefaultizedProps = C extends { defaultProps: infer D } ? Defaultize : P; + + type WithChildrenIfReactComponentClass> = C extends React.ComponentClass< + any + > + ? { children?: React.ReactNode } + : {}; + export type IntrinsicElementsKeys = keyof JSX.IntrinsicElements; + type WithOptionalTheme

= Omit & { + theme?: T; + }; + + type ForwardRefExoticBase

= Pick, keyof React.ForwardRefExoticComponent>; + + type StyledComponentPropsWithAs< + C extends string | React.ComponentType, + T extends object, + O extends object, + A extends keyof any, + F extends string | React.ComponentType = C + > = StyledComponentProps & { as?: C; forwardedAs?: F }; + + export type StyledComponentInnerOtherProps = C extends StyledComponent< + any, + any, + infer O, + any + > + ? O + : C extends StyledComponent + ? O + : never; + export type StyledComponentInnerAttrs = C extends StyledComponent + ? A + : never; + + export interface StyledComponentBase< + C extends string | React.ComponentType, + T extends object, + O extends object = {}, + A extends keyof any = never + > extends ForwardRefExoticBase> { + // add our own fake call signature to implement the polymorphic 'as' prop + (props: StyledComponentProps & { as?: never; forwardedAs?: never }): React.ReactElement< + StyledComponentProps + >; + = C, FAsC extends string | React.ComponentType = AsC>( + props: StyledComponentPropsWithAs, + ): React.ReactElement>; + + withComponent( + component: WithC, + ): StyledComponent< + ~~~~~~~~~~~~~~~~ + StyledComponentInnerComponent, + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + T, + ~~~~~~~~~~ + O & StyledComponentInnerOtherProps, + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + A | StyledComponentInnerAttrs + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + >; + ~~~~~ +!!! error TS2615: Type of property 'propTypes' circularly references itself in mapped type 'ForwardRefExoticBase & Partial>, "theme"> & { theme?: any; } & WithChildrenIfReactComponentClass>>'. + withComponent>( + component: WithC, + ): StyledComponent; + } + + export type StyledComponentInnerComponent> = C extends StyledComponent< + infer I, + any, + any, + any + > + ? I + : C extends StyledComponent + ? I + : C; + export type StyledComponentPropsWithRef< + C extends keyof JSX.IntrinsicElements | React.ComponentType + > = C extends AnyStyledComponent + ? React.ComponentPropsWithRef> // shouldn't have an instantiation limit error + : React.ComponentPropsWithRef; \ No newline at end of file diff --git a/tests/cases/compiler/genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts b/tests/cases/compiler/genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts new file mode 100644 index 0000000000000..3889f646205cb --- /dev/null +++ b/tests/cases/compiler/genericSignaturesConstrainedToDifferingGenericsNotCompatible.ts @@ -0,0 +1,18 @@ +// @strict: true +type Fn = (x: U) => U; + +type Concrete1 = (x: U) => U; +type Concrete2 = (x: U) => U; + +function f(t1: Fn, t2: Fn, c1: Concrete1, c2: Concrete2) { + // every single one of these assignments should error + + t1 = t2; + t2 = t1; + + c1 = c2; + c2 = c1; + + t1 = c1; + c1 = t1; +}