diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d7acedd663d94..47697d4ff23b5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8157,7 +8157,8 @@ namespace ts { function isSignatureAssignableTo(source: Signature, target: Signature, ignoreReturnTypes: boolean): boolean { - return compareSignaturesRelated(source, target, ignoreReturnTypes, /*reportErrors*/ false, /*errorReporter*/ undefined, compareTypesAssignable) !== Ternary.False; + return compareSignaturesRelated(source, target, /*checkAsCallback*/ false, ignoreReturnTypes, /*reportErrors*/ false, + /*errorReporter*/ undefined, compareTypesAssignable) !== Ternary.False; } type ErrorReporter = (message: DiagnosticMessage, arg0?: string, arg1?: string) => void; @@ -8167,6 +8168,7 @@ namespace ts { */ function compareSignaturesRelated(source: Signature, target: Signature, + checkAsCallback: boolean, ignoreReturnTypes: boolean, reportErrors: boolean, errorReporter: ErrorReporter, @@ -8209,9 +8211,23 @@ namespace ts { const sourceParams = source.parameters; const targetParams = target.parameters; for (let i = 0; i < checkCount; i++) { - const s = i < sourceMax ? getTypeOfParameter(sourceParams[i]) : getRestTypeOfSignature(source); - const t = i < targetMax ? getTypeOfParameter(targetParams[i]) : getRestTypeOfSignature(target); - const related = compareTypes(s, t, /*reportErrors*/ false) || compareTypes(t, s, reportErrors); + const sourceType = i < sourceMax ? getTypeOfParameter(sourceParams[i]) : getRestTypeOfSignature(source); + const targetType = i < targetMax ? getTypeOfParameter(targetParams[i]) : getRestTypeOfSignature(target); + const sourceSig = getSingleCallSignature(getNonNullableType(sourceType)); + const targetSig = getSingleCallSignature(getNonNullableType(targetType)); + // In order to ensure that any generic type Foo is at least co-variant with respect to T no matter + // how Foo uses T, we need to relate parameters bi-variantly (given that parameters are input positions, + // they naturally relate only contra-variantly). However, if the source and target parameters both have + // function types with a single call signature, we known we are relating two callback parameters. In + // that case it is sufficient to only relate the parameters of the signatures co-variantly because, + // similar to return values, callback parameters are output positions. This means that a Promise, + // where T is used only in callback parameter positions, will be co-variant (as opposed to bi-variant) + // with respect to T. + const callbacks = sourceSig && targetSig && !sourceSig.typePredicate && !targetSig.typePredicate && + (getFalsyFlags(sourceType) & TypeFlags.Nullable) === (getFalsyFlags(targetType) & TypeFlags.Nullable); + const related = callbacks ? + compareSignaturesRelated(targetSig, sourceSig, /*checkAsCallback*/ true, /*ignoreReturnTypes*/ false, reportErrors, errorReporter, compareTypes) : + !checkAsCallback && compareTypes(sourceType, targetType, /*reportErrors*/ false) || compareTypes(targetType, sourceType, reportErrors); if (!related) { if (reportErrors) { errorReporter(Diagnostics.Types_of_parameters_0_and_1_are_incompatible, @@ -8243,7 +8259,11 @@ namespace ts { } } else { - result &= compareTypes(sourceReturnType, targetReturnType, reportErrors); + // When relating callback signatures, we still need to relate return types bi-variantly as otherwise + // the containing type wouldn't be co-variant. For example, interface Foo { add(cb: () => T): void } + // wouldn't be co-variant for T without this rule. + result &= checkAsCallback && compareTypes(targetReturnType, sourceReturnType, /*reportErrors*/ false) || + compareTypes(sourceReturnType, targetReturnType, reportErrors); } } @@ -9210,7 +9230,7 @@ namespace ts { * See signatureAssignableTo, compareSignaturesIdentical */ function signatureRelatedTo(source: Signature, target: Signature, reportErrors: boolean): Ternary { - return compareSignaturesRelated(source, target, /*ignoreReturnTypes*/ false, reportErrors, reportError, isRelatedTo); + return compareSignaturesRelated(source, target, /*checkAsCallback*/ false, /*ignoreReturnTypes*/ false, reportErrors, reportError, isRelatedTo); } function signaturesIdenticalTo(source: Type, target: Type, kind: SignatureKind): Ternary { diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index a82d5b02b4402..94f169963baa2 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -57,7 +57,7 @@ namespace ts { // The visitXXX functions could be written as local functions that close over the cbNode and cbNodeArray // callback parameters, but that causes a closure allocation for each invocation with noticeable effects // on performance. - const visitNodes: (cb: (node: Node | Node[]) => T, nodes: Node[]) => T = cbNodeArray ? visitNodeArray : visitEachNode; + const visitNodes: (cb: ((node: Node) => T) | ((node: Node[]) => T), nodes: Node[]) => T = cbNodeArray ? visitNodeArray : visitEachNode; const cbNodes = cbNodeArray || cbNode; switch (node.kind) { case SyntaxKind.QualifiedName: diff --git a/src/compiler/visitor.ts b/src/compiler/visitor.ts index 297d2cc0dde3c..52f9ab0b8099e 100644 --- a/src/compiler/visitor.ts +++ b/src/compiler/visitor.ts @@ -885,7 +885,7 @@ namespace ts { return initial; } - const reduceNodes: (nodes: NodeArray, f: (memo: T, node: Node | NodeArray) => T, initial: T) => T = cbNodeArray ? reduceNodeArray : reduceLeft; + const reduceNodes: (nodes: NodeArray, f: ((memo: T, node: Node) => T) | ((memo: T, node: NodeArray) => T), initial: T) => T = cbNodeArray ? reduceNodeArray : reduceLeft; const cbNodes = cbNodeArray || cbNode; const kind = node.kind; diff --git a/tests/baselines/reference/assignmentCompatWithCallSignatures3.errors.txt b/tests/baselines/reference/assignmentCompatWithCallSignatures3.errors.txt new file mode 100644 index 0000000000000..0e8605efafdc7 --- /dev/null +++ b/tests/baselines/reference/assignmentCompatWithCallSignatures3.errors.txt @@ -0,0 +1,113 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts(71,1): error TS2322: Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '(x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U'. + Types of parameters 'y' and 'y' are incompatible. + Types of parameters 'arg2' and 'arg2' are incompatible. + Type 'Base' is not assignable to type '{ foo: string; bing: number; }'. + Property 'bing' is missing in type 'Base'. + + +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures3.ts (1 errors) ==== + // these are all permitted with the current rules, since we do not do contextual signature instantiation + + class Base { foo: string; } + class Derived extends Base { bar: string; } + class Derived2 extends Derived { baz: string; } + class OtherDerived extends Base { bing: string; } + + var a: (x: number) => number[]; + var a2: (x: number) => string[]; + var a3: (x: number) => void; + var a4: (x: string, y: number) => string; + var a5: (x: (arg: string) => number) => string; + var a6: (x: (arg: Base) => Derived) => Base; + var a7: (x: (arg: Base) => Derived) => (r: Base) => Derived; + var a8: (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived; + var a9: (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived; + var a10: (...x: Derived[]) => Derived; + var a11: (x: { foo: string }, y: { foo: string; bar: string }) => Base; + var a12: (x: Array, y: Array) => Array; + var a13: (x: Array, y: Array) => Array; + var a14: (x: { a: string; b: number }) => Object; + var a15: { + (x: number): number[]; + (x: string): string[]; + } + var a16: { + (x: T): number[]; + (x: U): number[]; + } + var a17: { + (x: (a: number) => number): number[]; + (x: (a: string) => string): string[]; + }; + var a18: { + (x: { + (a: number): number; + (a: string): string; + }): any[]; + (x: { + (a: boolean): boolean; + (a: Date): Date; + }): any[]; + } + + var b: (x: T) => T[]; + a = b; // ok + b = a; // ok + var b2: (x: T) => string[]; + a2 = b2; // ok + b2 = a2; // ok + var b3: (x: T) => T; + a3 = b3; // ok + b3 = a3; // ok + var b4: (x: T, y: U) => T; + a4 = b4; // ok + b4 = a4; // ok + var b5: (x: (arg: T) => U) => T; + a5 = b5; // ok + b5 = a5; // ok + var b6: (x: (arg: T) => U) => T; + a6 = b6; // ok + b6 = a6; // ok + var b7: (x: (arg: T) => U) => (r: T) => U; + a7 = b7; // ok + b7 = a7; // ok + var b8: (x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U; + a8 = b8; // ok + b8 = a8; // ok + var b9: (x: (arg: T) => U, y: (arg2: { foo: string; bing: number }) => U) => (r: T) => U; + a9 = b9; // ok + b9 = a9; // ok + ~~ +!!! error TS2322: Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '(x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U'. +!!! error TS2322: Types of parameters 'y' and 'y' are incompatible. +!!! error TS2322: Types of parameters 'arg2' and 'arg2' are incompatible. +!!! error TS2322: Type 'Base' is not assignable to type '{ foo: string; bing: number; }'. +!!! error TS2322: Property 'bing' is missing in type 'Base'. + var b10: (...x: T[]) => T; + a10 = b10; // ok + b10 = a10; // ok + var b11: (x: T, y: T) => T; + a11 = b11; // ok + b11 = a11; // ok + var b12: >(x: Array, y: T) => Array; + a12 = b12; // ok + b12 = a12; // ok + var b13: >(x: Array, y: T) => T; + a13 = b13; // ok + b13 = a13; // ok + var b14: (x: { a: T; b: T }) => T; + a14 = b14; // ok + b14 = a14; // ok + var b15: (x: T) => T[]; + a15 = b15; // ok + b15 = a15; // ok + var b16: (x: T) => number[]; + a16 = b16; // ok + b16 = a16; // ok + var b17: (x: (a: T) => T) => T[]; // ok + a17 = b17; // ok + b17 = a17; // ok + var b18: (x: (a: T) => T) => T[]; + a18 = b18; // ok + b18 = a18; // ok + \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt b/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt index 8d184edc085ef..df391b27f9873 100644 --- a/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithCallSignatures4.errors.txt @@ -1,17 +1,15 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(52,9): error TS2322: Type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived'. Types of parameters 'y' and 'y' are incompatible. - Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'. - Types of parameters 'arg2' and 'arg2' are incompatible. - Type '{ foo: number; }' is not assignable to type 'Base'. - Types of property 'foo' are incompatible. - Type 'number' is not assignable to type 'string'. + Types of parameters 'arg2' and 'arg2' are incompatible. + Type '{ foo: number; }' is not assignable to type 'Base'. + Types of property 'foo' are incompatible. + Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts(53,9): error TS2322: Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U'. Types of parameters 'y' and 'y' are incompatible. - Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived'. - Types of parameters 'arg2' and 'arg2' are incompatible. - Type 'Base' is not assignable to type '{ foo: number; }'. - Types of property 'foo' are incompatible. - Type 'string' is not assignable to type 'number'. + Types of parameters 'arg2' and 'arg2' are incompatible. + Type 'Base' is not assignable to type '{ foo: number; }'. + Types of property 'foo' are incompatible. + Type 'string' is not assignable to type 'number'. ==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithCallSignatures4.ts (2 errors) ==== @@ -70,20 +68,18 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme ~~ !!! error TS2322: Type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived'. !!! error TS2322: Types of parameters 'y' and 'y' are incompatible. -!!! error TS2322: Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'. -!!! error TS2322: Types of parameters 'arg2' and 'arg2' are incompatible. -!!! error TS2322: Type '{ foo: number; }' is not assignable to type 'Base'. -!!! error TS2322: Types of property 'foo' are incompatible. -!!! error TS2322: Type 'number' is not assignable to type 'string'. +!!! error TS2322: Types of parameters 'arg2' and 'arg2' are incompatible. +!!! error TS2322: Type '{ foo: number; }' is not assignable to type 'Base'. +!!! error TS2322: Types of property 'foo' are incompatible. +!!! error TS2322: Type 'number' is not assignable to type 'string'. b8 = a8; // error, { foo: number } and Base are incompatible ~~ !!! error TS2322: Type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U'. !!! error TS2322: Types of parameters 'y' and 'y' are incompatible. -!!! error TS2322: Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived'. -!!! error TS2322: Types of parameters 'arg2' and 'arg2' are incompatible. -!!! error TS2322: Type 'Base' is not assignable to type '{ foo: number; }'. -!!! error TS2322: Types of property 'foo' are incompatible. -!!! error TS2322: Type 'string' is not assignable to type 'number'. +!!! error TS2322: Types of parameters 'arg2' and 'arg2' are incompatible. +!!! error TS2322: Type 'Base' is not assignable to type '{ foo: number; }'. +!!! error TS2322: Types of property 'foo' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'number'. var b10: (...x: T[]) => T; diff --git a/tests/baselines/reference/assignmentCompatWithConstructSignatures3.errors.txt b/tests/baselines/reference/assignmentCompatWithConstructSignatures3.errors.txt new file mode 100644 index 0000000000000..995a9b67ccd72 --- /dev/null +++ b/tests/baselines/reference/assignmentCompatWithConstructSignatures3.errors.txt @@ -0,0 +1,113 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts(71,1): error TS2322: Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U'. + Types of parameters 'y' and 'y' are incompatible. + Types of parameters 'arg2' and 'arg2' are incompatible. + Type 'Base' is not assignable to type '{ foo: string; bing: number; }'. + Property 'bing' is missing in type 'Base'. + + +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures3.ts (1 errors) ==== + // checking assignment compatibility relations for function types. All of these are valid. + + class Base { foo: string; } + class Derived extends Base { bar: string; } + class Derived2 extends Derived { baz: string; } + class OtherDerived extends Base { bing: string; } + + var a: new (x: number) => number[]; + var a2: new (x: number) => string[]; + var a3: new (x: number) => void; + var a4: new (x: string, y: number) => string; + var a5: new (x: (arg: string) => number) => string; + var a6: new (x: (arg: Base) => Derived) => Base; + var a7: new (x: (arg: Base) => Derived) => (r: Base) => Derived; + var a8: new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived; + var a9: new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived; + var a10: new (...x: Derived[]) => Derived; + var a11: new (x: { foo: string }, y: { foo: string; bar: string }) => Base; + var a12: new (x: Array, y: Array) => Array; + var a13: new (x: Array, y: Array) => Array; + var a14: new (x: { a: string; b: number }) => Object; + var a15: { + new (x: number): number[]; + new (x: string): string[]; + } + var a16: { + new (x: T): number[]; + new (x: U): number[]; + } + var a17: { + new (x: new (a: number) => number): number[]; + new (x: new (a: string) => string): string[]; + }; + var a18: { + new (x: { + new (a: number): number; + new (a: string): string; + }): any[]; + new (x: { + new (a: boolean): boolean; + new (a: Date): Date; + }): any[]; + } + + var b: new (x: T) => T[]; + a = b; // ok + b = a; // ok + var b2: new (x: T) => string[]; + a2 = b2; // ok + b2 = a2; // ok + var b3: new (x: T) => T; + a3 = b3; // ok + b3 = a3; // ok + var b4: new (x: T, y: U) => T; + a4 = b4; // ok + b4 = a4; // ok + var b5: new (x: (arg: T) => U) => T; + a5 = b5; // ok + b5 = a5; // ok + var b6: new (x: (arg: T) => U) => T; + a6 = b6; // ok + b6 = a6; // ok + var b7: new (x: (arg: T) => U) => (r: T) => U; + a7 = b7; // ok + b7 = a7; // ok + var b8: new (x: (arg: T) => U, y: (arg2: T) => U) => (r: T) => U; + a8 = b8; // ok + b8 = a8; // ok + var b9: new (x: (arg: T) => U, y: (arg2: { foo: string; bing: number }) => U) => (r: T) => U; + a9 = b9; // ok + b9 = a9; // ok + ~~ +!!! error TS2322: Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U'. +!!! error TS2322: Types of parameters 'y' and 'y' are incompatible. +!!! error TS2322: Types of parameters 'arg2' and 'arg2' are incompatible. +!!! error TS2322: Type 'Base' is not assignable to type '{ foo: string; bing: number; }'. +!!! error TS2322: Property 'bing' is missing in type 'Base'. + var b10: new (...x: T[]) => T; + a10 = b10; // ok + b10 = a10; // ok + var b11: new (x: T, y: T) => T; + a11 = b11; // ok + b11 = a11; // ok + var b12: new >(x: Array, y: T) => Array; + a12 = b12; // ok + b12 = a12; // ok + var b13: new >(x: Array, y: T) => T; + a13 = b13; // ok + b13 = a13; // ok + var b14: new (x: { a: T; b: T }) => T; + a14 = b14; // ok + b14 = a14; // ok + var b15: new (x: T) => T[]; + a15 = b15; // ok + b15 = a15; // ok + var b16: new (x: T) => number[]; + a16 = b16; // ok + b16 = a16; // ok + var b17: new (x: new (a: T) => T) => T[]; // ok + a17 = b17; // ok + b17 = a17; // ok + var b18: new (x: new (a: T) => T) => T[]; + a18 = b18; // ok + b18 = a18; // ok + \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt b/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt index f6e93e13f0462..6b2f4a0de176d 100644 --- a/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithConstructSignatures4.errors.txt @@ -1,17 +1,15 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(52,9): error TS2322: Type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived'. Types of parameters 'y' and 'y' are incompatible. - Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'. - Types of parameters 'arg2' and 'arg2' are incompatible. - Type '{ foo: number; }' is not assignable to type 'Base'. - Types of property 'foo' are incompatible. - Type 'number' is not assignable to type 'string'. + Types of parameters 'arg2' and 'arg2' are incompatible. + Type '{ foo: number; }' is not assignable to type 'Base'. + Types of property 'foo' are incompatible. + Type 'number' is not assignable to type 'string'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(53,9): error TS2322: Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U'. Types of parameters 'y' and 'y' are incompatible. - Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived'. - Types of parameters 'arg2' and 'arg2' are incompatible. - Type 'Base' is not assignable to type '{ foo: number; }'. - Types of property 'foo' are incompatible. - Type 'string' is not assignable to type 'number'. + Types of parameters 'arg2' and 'arg2' are incompatible. + Type 'Base' is not assignable to type '{ foo: number; }'. + Types of property 'foo' are incompatible. + Type 'string' is not assignable to type 'number'. tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatWithConstructSignatures4.ts(77,9): error TS2322: Type 'new (x: (a: T) => T) => T[]' is not assignable to type '{ new (x: { new (a: number): number; new (a?: number): number; }): number[]; new (x: { new (a: boolean): boolean; new (a?: boolean): boolean; }): boolean[]; }'. Types of parameters 'x' and 'x' are incompatible. Type '{ new (a: number): number; new (a?: number): number; }' is not assignable to type '(a: any) => any'. @@ -86,20 +84,18 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignme ~~ !!! error TS2322: Type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived'. !!! error TS2322: Types of parameters 'y' and 'y' are incompatible. -!!! error TS2322: Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'. -!!! error TS2322: Types of parameters 'arg2' and 'arg2' are incompatible. -!!! error TS2322: Type '{ foo: number; }' is not assignable to type 'Base'. -!!! error TS2322: Types of property 'foo' are incompatible. -!!! error TS2322: Type 'number' is not assignable to type 'string'. +!!! error TS2322: Types of parameters 'arg2' and 'arg2' are incompatible. +!!! error TS2322: Type '{ foo: number; }' is not assignable to type 'Base'. +!!! error TS2322: Types of property 'foo' are incompatible. +!!! error TS2322: Type 'number' is not assignable to type 'string'. b8 = a8; // error ~~ !!! error TS2322: Type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived' is not assignable to type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U'. !!! error TS2322: Types of parameters 'y' and 'y' are incompatible. -!!! error TS2322: Type '(arg2: { foo: number; }) => any' is not assignable to type '(arg2: Base) => Derived'. -!!! error TS2322: Types of parameters 'arg2' and 'arg2' are incompatible. -!!! error TS2322: Type 'Base' is not assignable to type '{ foo: number; }'. -!!! error TS2322: Types of property 'foo' are incompatible. -!!! error TS2322: Type 'string' is not assignable to type 'number'. +!!! error TS2322: Types of parameters 'arg2' and 'arg2' are incompatible. +!!! error TS2322: Type 'Base' is not assignable to type '{ foo: number; }'. +!!! error TS2322: Types of property 'foo' are incompatible. +!!! error TS2322: Type 'string' is not assignable to type 'number'. var b10: new (...x: T[]) => T; diff --git a/tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt b/tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt index 2d7e795d26ab7..f5e05567b2580 100644 --- a/tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt +++ b/tests/baselines/reference/callSignatureAssignabilityInInheritance3.errors.txt @@ -7,11 +7,10 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign Types of property 'a8' are incompatible. Type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived'. Types of parameters 'y' and 'y' are incompatible. - Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'. - Types of parameters 'arg2' and 'arg2' are incompatible. - Type '{ foo: number; }' is not assignable to type 'Base'. - Types of property 'foo' are incompatible. - Type 'number' is not assignable to type 'string'. + Types of parameters 'arg2' and 'arg2' are incompatible. + Type '{ foo: number; }' is not assignable to type 'Base'. + Types of property 'foo' are incompatible. + Type 'number' is not assignable to type 'string'. ==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSignatureAssignabilityInInheritance3.ts (2 errors) ==== @@ -86,11 +85,10 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/callSign !!! error TS2430: Types of property 'a8' are incompatible. !!! error TS2430: Type '(x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type '(x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived'. !!! error TS2430: Types of parameters 'y' and 'y' are incompatible. -!!! error TS2430: Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'. -!!! error TS2430: Types of parameters 'arg2' and 'arg2' are incompatible. -!!! error TS2430: Type '{ foo: number; }' is not assignable to type 'Base'. -!!! error TS2430: Types of property 'foo' are incompatible. -!!! error TS2430: Type 'number' is not assignable to type 'string'. +!!! error TS2430: Types of parameters 'arg2' and 'arg2' are incompatible. +!!! error TS2430: Type '{ foo: number; }' is not assignable to type 'Base'. +!!! error TS2430: Types of property 'foo' are incompatible. +!!! error TS2430: Type 'number' is not assignable to type 'string'. a8: (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U; // error, type mismatch } diff --git a/tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt b/tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt index 086372aac179f..7bd761593912f 100644 --- a/tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt +++ b/tests/baselines/reference/constructSignatureAssignabilityInInheritance3.errors.txt @@ -7,11 +7,10 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/construc Types of property 'a8' are incompatible. Type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived'. Types of parameters 'y' and 'y' are incompatible. - Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'. - Types of parameters 'arg2' and 'arg2' are incompatible. - Type '{ foo: number; }' is not assignable to type 'Base'. - Types of property 'foo' are incompatible. - Type 'number' is not assignable to type 'string'. + Types of parameters 'arg2' and 'arg2' are incompatible. + Type '{ foo: number; }' is not assignable to type 'Base'. + Types of property 'foo' are incompatible. + Type 'number' is not assignable to type 'string'. ==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/constructSignatureAssignabilityInInheritance3.ts (2 errors) ==== @@ -76,11 +75,10 @@ tests/cases/conformance/types/typeRelationships/assignmentCompatibility/construc !!! error TS2430: Types of property 'a8' are incompatible. !!! error TS2430: Type 'new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U' is not assignable to type 'new (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived'. !!! error TS2430: Types of parameters 'y' and 'y' are incompatible. -!!! error TS2430: Type '(arg2: Base) => Derived' is not assignable to type '(arg2: { foo: number; }) => any'. -!!! error TS2430: Types of parameters 'arg2' and 'arg2' are incompatible. -!!! error TS2430: Type '{ foo: number; }' is not assignable to type 'Base'. -!!! error TS2430: Types of property 'foo' are incompatible. -!!! error TS2430: Type 'number' is not assignable to type 'string'. +!!! error TS2430: Types of parameters 'arg2' and 'arg2' are incompatible. +!!! error TS2430: Type '{ foo: number; }' is not assignable to type 'Base'. +!!! error TS2430: Types of property 'foo' are incompatible. +!!! error TS2430: Type 'number' is not assignable to type 'string'. a8: new (x: (arg: T) => U, y: (arg2: { foo: number; }) => U) => (r: T) => U; // error, type mismatch } diff --git a/tests/baselines/reference/covariantCallbacks.errors.txt b/tests/baselines/reference/covariantCallbacks.errors.txt new file mode 100644 index 0000000000000..55c69c89728f1 --- /dev/null +++ b/tests/baselines/reference/covariantCallbacks.errors.txt @@ -0,0 +1,132 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts(12,5): error TS2322: Type 'P' is not assignable to type 'P'. + Type 'A' is not assignable to type 'B'. + Property 'b' is missing in type 'A'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts(17,5): error TS2322: Type 'Promise' is not assignable to type 'Promise'. + Type 'A' is not assignable to type 'B'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts(30,5): error TS2322: Type 'AList1' is not assignable to type 'BList1'. + Types of property 'forEach' are incompatible. + Type '(cb: (item: A) => void) => void' is not assignable to type '(cb: (item: B) => void) => void'. + Types of parameters 'cb' and 'cb' are incompatible. + Types of parameters 'item' and 'item' are incompatible. + Type 'A' is not assignable to type 'B'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts(43,5): error TS2322: Type 'AList2' is not assignable to type 'BList2'. + Types of property 'forEach' are incompatible. + Type '(cb: (item: A) => boolean) => void' is not assignable to type '(cb: (item: A) => void) => void'. + Types of parameters 'cb' and 'cb' are incompatible. + Type 'void' is not assignable to type 'boolean'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts(56,5): error TS2322: Type 'AList3' is not assignable to type 'BList3'. + Types of property 'forEach' are incompatible. + Type '(cb: (item: A) => void) => void' is not assignable to type '(cb: (item: A, context: any) => void) => void'. + Types of parameters 'cb' and 'cb' are incompatible. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts(69,5): error TS2322: Type 'AList4' is not assignable to type 'BList4'. + Types of property 'forEach' are incompatible. + Type '(cb: (item: A) => A) => void' is not assignable to type '(cb: (item: B) => B) => void'. + Types of parameters 'cb' and 'cb' are incompatible. + Types of parameters 'item' and 'item' are incompatible. + Type 'A' is not assignable to type 'B'. + + +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts (6 errors) ==== + // Test that callback parameters are related covariantly + + interface P { + then(cb: (value: T) => void): void; + }; + + interface A { a: string } + interface B extends A { b: string } + + function f1(a: P, b: P) { + a = b; + b = a; // Error + ~ +!!! error TS2322: Type 'P' is not assignable to type 'P'. +!!! error TS2322: Type 'A' is not assignable to type 'B'. +!!! error TS2322: Property 'b' is missing in type 'A'. + } + + function f2(a: Promise, b: Promise) { + a = b; + b = a; // Error + ~ +!!! error TS2322: Type 'Promise' is not assignable to type 'Promise'. +!!! error TS2322: Type 'A' is not assignable to type 'B'. + } + + interface AList1 { + forEach(cb: (item: A) => void): void; + } + + interface BList1 { + forEach(cb: (item: B) => void): void; + } + + function f11(a: AList1, b: BList1) { + a = b; + b = a; // Error + ~ +!!! error TS2322: Type 'AList1' is not assignable to type 'BList1'. +!!! error TS2322: Types of property 'forEach' are incompatible. +!!! error TS2322: Type '(cb: (item: A) => void) => void' is not assignable to type '(cb: (item: B) => void) => void'. +!!! error TS2322: Types of parameters 'cb' and 'cb' are incompatible. +!!! error TS2322: Types of parameters 'item' and 'item' are incompatible. +!!! error TS2322: Type 'A' is not assignable to type 'B'. + } + + interface AList2 { + forEach(cb: (item: A) => boolean): void; + } + + interface BList2 { + forEach(cb: (item: A) => void): void; + } + + function f12(a: AList2, b: BList2) { + a = b; + b = a; // Error + ~ +!!! error TS2322: Type 'AList2' is not assignable to type 'BList2'. +!!! error TS2322: Types of property 'forEach' are incompatible. +!!! error TS2322: Type '(cb: (item: A) => boolean) => void' is not assignable to type '(cb: (item: A) => void) => void'. +!!! error TS2322: Types of parameters 'cb' and 'cb' are incompatible. +!!! error TS2322: Type 'void' is not assignable to type 'boolean'. + } + + interface AList3 { + forEach(cb: (item: A) => void): void; + } + + interface BList3 { + forEach(cb: (item: A, context: any) => void): void; + } + + function f13(a: AList3, b: BList3) { + a = b; + b = a; // Error + ~ +!!! error TS2322: Type 'AList3' is not assignable to type 'BList3'. +!!! error TS2322: Types of property 'forEach' are incompatible. +!!! error TS2322: Type '(cb: (item: A) => void) => void' is not assignable to type '(cb: (item: A, context: any) => void) => void'. +!!! error TS2322: Types of parameters 'cb' and 'cb' are incompatible. + } + + interface AList4 { + forEach(cb: (item: A) => A): void; + } + + interface BList4 { + forEach(cb: (item: B) => B): void; + } + + function f14(a: AList4, b: BList4) { + a = b; + b = a; // Error + ~ +!!! error TS2322: Type 'AList4' is not assignable to type 'BList4'. +!!! error TS2322: Types of property 'forEach' are incompatible. +!!! error TS2322: Type '(cb: (item: A) => A) => void' is not assignable to type '(cb: (item: B) => B) => void'. +!!! error TS2322: Types of parameters 'cb' and 'cb' are incompatible. +!!! error TS2322: Types of parameters 'item' and 'item' are incompatible. +!!! error TS2322: Type 'A' is not assignable to type 'B'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/covariantCallbacks.js b/tests/baselines/reference/covariantCallbacks.js new file mode 100644 index 0000000000000..4678c13bf15e4 --- /dev/null +++ b/tests/baselines/reference/covariantCallbacks.js @@ -0,0 +1,101 @@ +//// [covariantCallbacks.ts] +// Test that callback parameters are related covariantly + +interface P { + then(cb: (value: T) => void): void; +}; + +interface A { a: string } +interface B extends A { b: string } + +function f1(a: P, b: P) { + a = b; + b = a; // Error +} + +function f2(a: Promise, b: Promise) { + a = b; + b = a; // Error +} + +interface AList1 { + forEach(cb: (item: A) => void): void; +} + +interface BList1 { + forEach(cb: (item: B) => void): void; +} + +function f11(a: AList1, b: BList1) { + a = b; + b = a; // Error +} + +interface AList2 { + forEach(cb: (item: A) => boolean): void; +} + +interface BList2 { + forEach(cb: (item: A) => void): void; +} + +function f12(a: AList2, b: BList2) { + a = b; + b = a; // Error +} + +interface AList3 { + forEach(cb: (item: A) => void): void; +} + +interface BList3 { + forEach(cb: (item: A, context: any) => void): void; +} + +function f13(a: AList3, b: BList3) { + a = b; + b = a; // Error +} + +interface AList4 { + forEach(cb: (item: A) => A): void; +} + +interface BList4 { + forEach(cb: (item: B) => B): void; +} + +function f14(a: AList4, b: BList4) { + a = b; + b = a; // Error +} + + +//// [covariantCallbacks.js] +"use strict"; +// Test that callback parameters are related covariantly +; +function f1(a, b) { + a = b; + b = a; // Error +} +function f2(a, b) { + a = b; + b = a; // Error +} +function f11(a, b) { + a = b; + b = a; // Error +} +function f12(a, b) { + a = b; + b = a; // Error +} +function f13(a, b) { + a = b; + b = a; // Error +} +function f14(a, b) { + a = b; + b = a; // Error +} diff --git a/tests/baselines/reference/optionalFunctionArgAssignability.errors.txt b/tests/baselines/reference/optionalFunctionArgAssignability.errors.txt index 024c5c1ea2b4d..1898db924635b 100644 --- a/tests/baselines/reference/optionalFunctionArgAssignability.errors.txt +++ b/tests/baselines/reference/optionalFunctionArgAssignability.errors.txt @@ -1,8 +1,7 @@ tests/cases/compiler/optionalFunctionArgAssignability.ts(7,1): error TS2322: Type '(onFulFill?: (value: number) => U, onReject?: (reason: any) => U) => Promise' is not assignable to type '(onFulfill?: (value: string) => U, onReject?: (reason: any) => U) => Promise'. Types of parameters 'onFulFill' and 'onFulfill' are incompatible. - Type '(value: string) => any' is not assignable to type '(value: number) => any'. - Types of parameters 'value' and 'value' are incompatible. - Type 'number' is not assignable to type 'string'. + Types of parameters 'value' and 'value' are incompatible. + Type 'number' is not assignable to type 'string'. ==== tests/cases/compiler/optionalFunctionArgAssignability.ts (1 errors) ==== @@ -16,7 +15,6 @@ tests/cases/compiler/optionalFunctionArgAssignability.ts(7,1): error TS2322: Typ ~ !!! error TS2322: Type '(onFulFill?: (value: number) => U, onReject?: (reason: any) => U) => Promise' is not assignable to type '(onFulfill?: (value: string) => U, onReject?: (reason: any) => U) => Promise'. !!! error TS2322: Types of parameters 'onFulFill' and 'onFulfill' are incompatible. -!!! error TS2322: Type '(value: string) => any' is not assignable to type '(value: number) => any'. -!!! error TS2322: Types of parameters 'value' and 'value' are incompatible. -!!! error TS2322: Type 'number' is not assignable to type 'string'. +!!! error TS2322: Types of parameters 'value' and 'value' are incompatible. +!!! error TS2322: Type 'number' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/overloadOnConstNoAnyImplementation.errors.txt b/tests/baselines/reference/overloadOnConstNoAnyImplementation.errors.txt index 0573c6ed79ee6..aa7bbf7723968 100644 --- a/tests/baselines/reference/overloadOnConstNoAnyImplementation.errors.txt +++ b/tests/baselines/reference/overloadOnConstNoAnyImplementation.errors.txt @@ -1,8 +1,11 @@ +tests/cases/compiler/overloadOnConstNoAnyImplementation.ts(1,10): error TS2394: Overload signature is not compatible with function implementation. tests/cases/compiler/overloadOnConstNoAnyImplementation.ts(9,8): error TS2345: Argument of type '1' is not assignable to parameter of type 'string'. -==== tests/cases/compiler/overloadOnConstNoAnyImplementation.ts (1 errors) ==== +==== tests/cases/compiler/overloadOnConstNoAnyImplementation.ts (2 errors) ==== function x1(a: number, cb: (x: 'hi') => number); + ~~ +!!! error TS2394: Overload signature is not compatible with function implementation. function x1(a: number, cb: (x: 'bye') => number); function x1(a: number, cb: (x: string) => number) { cb('hi'); diff --git a/tests/baselines/reference/overloadOnConstNoAnyImplementation2.errors.txt b/tests/baselines/reference/overloadOnConstNoAnyImplementation2.errors.txt index 24047578ec6a1..a090f370863f5 100644 --- a/tests/baselines/reference/overloadOnConstNoAnyImplementation2.errors.txt +++ b/tests/baselines/reference/overloadOnConstNoAnyImplementation2.errors.txt @@ -1,3 +1,4 @@ +tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts(6,5): error TS2394: Overload signature is not compatible with function implementation. tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts(12,18): error TS2345: Argument of type '1' is not assignable to parameter of type 'string'. tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts(18,9): error TS2345: Argument of type '(x: "bye") => number' is not assignable to parameter of type '(x: "hi") => number'. Types of parameters 'x' and 'x' are incompatible. @@ -7,13 +8,15 @@ tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts(21,9): error TS2345: Type '"hi"' is not assignable to type 'number'. -==== tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts (3 errors) ==== +==== tests/cases/compiler/overloadOnConstNoAnyImplementation2.ts (4 errors) ==== interface I { x1(a: number, callback: (x: 'hi') => number); } class C { x1(a: number, callback: (x: 'hi') => number); + ~~ +!!! error TS2394: Overload signature is not compatible with function implementation. x1(a: number, callback: (x: string) => number) { callback('hi'); callback('bye'); diff --git a/tests/baselines/reference/promisePermutations.errors.txt b/tests/baselines/reference/promisePermutations.errors.txt index e5e7f2109a963..8b46f18666fde 100644 --- a/tests/baselines/reference/promisePermutations.errors.txt +++ b/tests/baselines/reference/promisePermutations.errors.txt @@ -31,16 +31,16 @@ tests/cases/compiler/promisePermutations.ts(110,19): error TS2345: Argument of t tests/cases/compiler/promisePermutations.ts(111,19): error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. Types of parameters 'cb' and 'value' are incompatible. Type 'string' is not assignable to type '(a: T) => T'. -tests/cases/compiler/promisePermutations.ts(117,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations.ts(121,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +tests/cases/compiler/promisePermutations.ts(117,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations.ts(121,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations.ts(122,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations.ts(126,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations.ts(126,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations.ts(129,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' is not a valid type argument because it is not a supertype of candidate 'IPromise'. Type 'string' is not assignable to type 'number'. -tests/cases/compiler/promisePermutations.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations.ts(133,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +tests/cases/compiler/promisePermutations.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations.ts(133,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations.ts(134,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. 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' is not a valid type argument because it is not a supertype of candidate 'IPromise'. @@ -51,9 +51,8 @@ tests/cases/compiler/promisePermutations.ts(152,12): error TS2453: The type argu Types of property 'then' are incompatible. Type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }'. Types of parameters 'success' and 'onfulfilled' are incompatible. - Type '(value: number) => any' is not assignable to type '(value: string) => IPromise'. - Types of parameters 'value' and 'value' are incompatible. - Type 'string' is not assignable to type 'number'. + Types of parameters 'value' and 'value' are incompatible. + Type 'string' is not assignable to type 'number'. tests/cases/compiler/promisePermutations.ts(156,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. Type 'IPromise' is not assignable to type 'IPromise'. Type 'number' is not assignable to type 'string'. @@ -67,9 +66,8 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t Types of property 'then' are incompatible. Type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }' is not assignable to type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }'. Types of parameters 'onfulfilled' and 'success' are incompatible. - Type '(value: string) => IPromise' is not assignable to type '(value: number) => any'. - Types of parameters 'value' and 'value' are incompatible. - Type 'number' is not assignable to type 'string'. + Types of parameters 'value' and 'value' are incompatible. + Type 'number' is not assignable to type 'string'. ==== tests/cases/compiler/promisePermutations.ts (33 errors) ==== @@ -241,15 +239,15 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t var nPromise: (x: any) => Promise; var r8a = r8.then(testFunction8, testFunction8, testFunction8); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var r8b = r8.then(nIPromise, nIPromise, nIPromise).then(nIPromise, nIPromise, nIPromise); // ok var s8: Promise; var s8a = s8.then(testFunction8, testFunction8, testFunction8); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var s8b = s8.then(testFunction8P, testFunction8P, testFunction8P); // error ~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. var s8c = s8.then(testFunction8P, testFunction8, testFunction8); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. @@ -258,7 +256,7 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t var r9: IPromise; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok var r9d = r9.then(testFunction, sIPromise, nIPromise); // ok @@ -270,10 +268,10 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error ~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. @@ -307,9 +305,8 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t !!! error TS2453: Types of property 'then' are incompatible. !!! error TS2453: Type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }'. !!! error TS2453: Types of parameters 'success' and 'onfulfilled' are incompatible. -!!! error TS2453: Type '(value: number) => any' is not assignable to type '(value: string) => IPromise'. -!!! error TS2453: Types of parameters 'value' and 'value' are incompatible. -!!! error TS2453: Type 'string' is not assignable to type 'number'. +!!! error TS2453: Types of parameters 'value' and 'value' are incompatible. +!!! error TS2453: Type 'string' is not assignable to type 'number'. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; @@ -335,9 +332,8 @@ tests/cases/compiler/promisePermutations.ts(160,21): error TS2345: Argument of t !!! error TS2345: Types of property 'then' are incompatible. !!! error TS2345: Type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }' is not assignable to type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }'. !!! error TS2345: Types of parameters 'onfulfilled' and 'success' are incompatible. -!!! error TS2345: Type '(value: string) => IPromise' is not assignable to type '(value: number) => any'. -!!! error TS2345: Types of parameters 'value' and 'value' are incompatible. -!!! error TS2345: Type 'number' is not assignable to type 'string'. +!!! error TS2345: Types of parameters 'value' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok diff --git a/tests/baselines/reference/promisePermutations2.errors.txt b/tests/baselines/reference/promisePermutations2.errors.txt index 26fec6b2fd118..32df80e20f148 100644 --- a/tests/baselines/reference/promisePermutations2.errors.txt +++ b/tests/baselines/reference/promisePermutations2.errors.txt @@ -31,16 +31,16 @@ tests/cases/compiler/promisePermutations2.ts(109,19): error TS2345: Argument of tests/cases/compiler/promisePermutations2.ts(110,19): error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. Types of parameters 'cb' and 'value' are incompatible. Type 'string' is not assignable to type '(a: T) => T'. -tests/cases/compiler/promisePermutations2.ts(116,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations2.ts(119,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations2.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +tests/cases/compiler/promisePermutations2.ts(116,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations2.ts(119,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations2.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations2.ts(121,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations2.ts(125,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations2.ts(125,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations2.ts(128,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' is not a valid type argument because it is not a supertype of candidate 'IPromise'. Type 'string' is not assignable to type 'number'. -tests/cases/compiler/promisePermutations2.ts(131,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations2.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +tests/cases/compiler/promisePermutations2.ts(131,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations2.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations2.ts(133,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. 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' is not a valid type argument because it is not a supertype of candidate 'IPromise'. @@ -51,9 +51,8 @@ tests/cases/compiler/promisePermutations2.ts(151,12): error TS2453: The type arg Types of property 'then' are incompatible. Type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }'. Types of parameters 'success' and 'onfulfilled' are incompatible. - Type '(value: number) => any' is not assignable to type '(value: string) => IPromise'. - Types of parameters 'value' and 'value' are incompatible. - Type 'string' is not assignable to type 'number'. + Types of parameters 'value' and 'value' are incompatible. + Type 'string' is not assignable to type 'number'. tests/cases/compiler/promisePermutations2.ts(155,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. Type 'IPromise' is not assignable to type 'IPromise'. Type 'number' is not assignable to type 'string'. @@ -67,9 +66,8 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of Types of property 'then' are incompatible. Type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }' is not assignable to type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }'. Types of parameters 'onfulfilled' and 'success' are incompatible. - Type '(value: string) => IPromise' is not assignable to type '(value: number) => any'. - Types of parameters 'value' and 'value' are incompatible. - Type 'number' is not assignable to type 'string'. + Types of parameters 'value' and 'value' are incompatible. + Type 'number' is not assignable to type 'string'. ==== tests/cases/compiler/promisePermutations2.ts (33 errors) ==== @@ -240,15 +238,15 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var nPromise: (x: any) => Promise; var r8a = r8.then(testFunction8, testFunction8, testFunction8); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var r8b = r8.then(nIPromise, nIPromise, nIPromise).then(nIPromise, nIPromise, nIPromise); // ok var s8: Promise; var s8a = s8.then(testFunction8, testFunction8, testFunction8); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var s8b = s8.then(testFunction8P, testFunction8P, testFunction8P); // error ~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. var s8c = s8.then(testFunction8P, testFunction8, testFunction8); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. @@ -257,7 +255,7 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var r9: IPromise; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok var r9d = r9.then(testFunction, sIPromise, nIPromise); // error @@ -269,10 +267,10 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error ~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. @@ -306,9 +304,8 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of !!! error TS2453: Types of property 'then' are incompatible. !!! error TS2453: Type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }' is not assignable to type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }'. !!! error TS2453: Types of parameters 'success' and 'onfulfilled' are incompatible. -!!! error TS2453: Type '(value: number) => any' is not assignable to type '(value: string) => IPromise'. -!!! error TS2453: Types of parameters 'value' and 'value' are incompatible. -!!! error TS2453: Type 'string' is not assignable to type 'number'. +!!! error TS2453: Types of parameters 'value' and 'value' are incompatible. +!!! error TS2453: Type 'string' is not assignable to type 'number'. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; @@ -334,9 +331,8 @@ tests/cases/compiler/promisePermutations2.ts(159,21): error TS2345: Argument of !!! error TS2345: Types of property 'then' are incompatible. !!! error TS2345: Type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }' is not assignable to type '{ (success?: (value: string) => IPromise, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => IPromise, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => IPromise, progress?: (progress: any) => void): IPromise; (success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void): IPromise; }'. !!! error TS2345: Types of parameters 'onfulfilled' and 'success' are incompatible. -!!! error TS2345: Type '(value: string) => IPromise' is not assignable to type '(value: number) => any'. -!!! error TS2345: Types of parameters 'value' and 'value' are incompatible. -!!! error TS2345: Type 'number' is not assignable to type 'string'. +!!! error TS2345: Types of parameters 'value' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok diff --git a/tests/baselines/reference/promisePermutations3.errors.txt b/tests/baselines/reference/promisePermutations3.errors.txt index 1354f486fcb26..3d9fc1b2d26dd 100644 --- a/tests/baselines/reference/promisePermutations3.errors.txt +++ b/tests/baselines/reference/promisePermutations3.errors.txt @@ -34,16 +34,16 @@ tests/cases/compiler/promisePermutations3.ts(109,19): error TS2345: Argument of tests/cases/compiler/promisePermutations3.ts(110,19): error TS2345: Argument of type '(cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: string) => IPromise'. Types of parameters 'cb' and 'value' are incompatible. Type 'string' is not assignable to type '(a: T) => T'. -tests/cases/compiler/promisePermutations3.ts(116,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations3.ts(119,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations3.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +tests/cases/compiler/promisePermutations3.ts(116,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations3.ts(119,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations3.ts(120,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations3.ts(121,19): error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations3.ts(125,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations3.ts(125,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. tests/cases/compiler/promisePermutations3.ts(128,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' is not a valid type argument because it is not a supertype of candidate 'IPromise'. Type 'string' is not assignable to type 'number'. -tests/cases/compiler/promisePermutations3.ts(131,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. -tests/cases/compiler/promisePermutations3.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +tests/cases/compiler/promisePermutations3.ts(131,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +tests/cases/compiler/promisePermutations3.ts(132,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. tests/cases/compiler/promisePermutations3.ts(133,19): error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. 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' is not a valid type argument because it is not a supertype of candidate 'IPromise'. @@ -54,9 +54,8 @@ tests/cases/compiler/promisePermutations3.ts(151,12): error TS2453: The type arg Types of property 'then' are incompatible. Type '(success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void) => IPromise' is not assignable to type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }'. Types of parameters 'success' and 'onfulfilled' are incompatible. - Type '(value: number) => any' is not assignable to type '(value: string) => any'. - Types of parameters 'value' and 'value' are incompatible. - Type 'string' is not assignable to type 'number'. + Types of parameters 'value' and 'value' are incompatible. + Type 'string' is not assignable to type 'number'. tests/cases/compiler/promisePermutations3.ts(155,21): error TS2345: Argument of type '{ (x: number): IPromise; (x: string): IPromise; }' is not assignable to parameter of type '(value: number) => IPromise'. Type 'IPromise' is not assignable to type 'IPromise'. Type 'number' is not assignable to type 'string'. @@ -70,9 +69,8 @@ tests/cases/compiler/promisePermutations3.ts(159,21): error TS2345: Argument of Types of property 'then' are incompatible. Type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }' is not assignable to type '(success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void) => IPromise'. Types of parameters 'onfulfilled' and 'success' are incompatible. - Type '(value: string) => any' is not assignable to type '(value: number) => any'. - Types of parameters 'value' and 'value' are incompatible. - Type 'number' is not assignable to type 'string'. + Types of parameters 'value' and 'value' are incompatible. + Type 'number' is not assignable to type 'string'. tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of type '{ (x: T): IPromise; (x: T, y: T): Promise; }' is not assignable to parameter of type '(value: (x: any) => any) => Promise'. Type 'IPromise' is not assignable to type 'Promise'. Types of property 'then' are incompatible. @@ -252,15 +250,15 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var nPromise: (x: any) => Promise; var r8a = r8.then(testFunction8, testFunction8, testFunction8); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var r8b = r8.then(nIPromise, nIPromise, nIPromise).then(nIPromise, nIPromise, nIPromise); // ok var s8: Promise; var s8a = s8.then(testFunction8, testFunction8, testFunction8); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var s8b = s8.then(testFunction8P, testFunction8P, testFunction8P); // error ~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => Promise'. var s8c = s8.then(testFunction8P, testFunction8, testFunction8); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: T, cb: (a: T) => T) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. @@ -269,7 +267,7 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var r9: IPromise; var r9a = r9.then(testFunction9, testFunction9, testFunction9); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var r9b = r9.then(sIPromise, sIPromise, sIPromise); // ok var r9c = r9.then(nIPromise, nIPromise, nIPromise); // ok var r9d = r9.then(testFunction, sIPromise, nIPromise); // error @@ -281,10 +279,10 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of var s9: Promise; var s9a = s9.then(testFunction9, testFunction9, testFunction9); // error ~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => IPromise' is not assignable to parameter of type '(value: number) => IPromise'. var s9b = s9.then(testFunction9P, testFunction9P, testFunction9P); // error ~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. +!!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => Promise'. var s9c = s9.then(testFunction9P, testFunction9, testFunction9); // error ~~~~~~~~~~~~~~ !!! error TS2345: Argument of type '(x: T, cb: (a: U) => U) => Promise' is not assignable to parameter of type '(value: number) => IPromise'. @@ -318,9 +316,8 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of !!! error TS2453: Types of property 'then' are incompatible. !!! error TS2453: Type '(success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void) => IPromise' is not assignable to type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }'. !!! error TS2453: Types of parameters 'success' and 'onfulfilled' are incompatible. -!!! error TS2453: Type '(value: number) => any' is not assignable to type '(value: string) => any'. -!!! error TS2453: Types of parameters 'value' and 'value' are incompatible. -!!! error TS2453: Type 'string' is not assignable to type 'number'. +!!! error TS2453: Types of parameters 'value' and 'value' are incompatible. +!!! error TS2453: Type 'string' is not assignable to type 'number'. var s10g = s10.then(testFunctionP, nIPromise, sIPromise).then(sPromise, sIPromise, sIPromise); // ok var r11: IPromise; @@ -346,9 +343,8 @@ tests/cases/compiler/promisePermutations3.ts(165,21): error TS2345: Argument of !!! error TS2345: Types of property 'then' are incompatible. !!! error TS2345: Type '{ (onfulfilled?: (value: number) => TResult1 | PromiseLike, onrejected?: (reason: any) => TResult2 | PromiseLike): Promise; (success?: (value: number) => Promise, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => Promise, error?: (error: any) => U, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => Promise, progress?: (progress: any) => void): Promise; (success?: (value: number) => U, error?: (error: any) => U, progress?: (progress: any) => void): Promise; }' is not assignable to type '(success?: (value: string) => U, error?: (error: any) => U, progress?: (progress: any) => void) => IPromise'. !!! error TS2345: Types of parameters 'onfulfilled' and 'success' are incompatible. -!!! error TS2345: Type '(value: string) => any' is not assignable to type '(value: number) => any'. -!!! error TS2345: Types of parameters 'value' and 'value' are incompatible. -!!! error TS2345: Type 'number' is not assignable to type 'string'. +!!! error TS2345: Types of parameters 'value' and 'value' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. var r12 = testFunction12(x => x); var r12a = r12.then(testFunction12, testFunction12, testFunction12); // ok diff --git a/tests/baselines/reference/promisesWithConstraints.errors.txt b/tests/baselines/reference/promisesWithConstraints.errors.txt new file mode 100644 index 0000000000000..d2c459da28486 --- /dev/null +++ b/tests/baselines/reference/promisesWithConstraints.errors.txt @@ -0,0 +1,36 @@ +tests/cases/compiler/promisesWithConstraints.ts(15,1): error TS2322: Type 'Promise' is not assignable to type 'Promise'. + Type 'Foo' is not assignable to type 'Bar'. + Property 'y' is missing in type 'Foo'. +tests/cases/compiler/promisesWithConstraints.ts(20,1): error TS2322: Type 'CPromise' is not assignable to type 'CPromise'. + Type 'Foo' is not assignable to type 'Bar'. + + +==== tests/cases/compiler/promisesWithConstraints.ts (2 errors) ==== + interface Promise { + then(cb: (x: T) => Promise): Promise; + } + + interface CPromise { + then(cb: (x: T) => Promise): Promise; + } + + interface Foo { x; } + interface Bar { x; y; } + + var a: Promise; + var b: Promise; + a = b; // ok + b = a; // ok + ~ +!!! error TS2322: Type 'Promise' is not assignable to type 'Promise'. +!!! error TS2322: Type 'Foo' is not assignable to type 'Bar'. +!!! error TS2322: Property 'y' is missing in type 'Foo'. + + var a2: CPromise; + var b2: CPromise; + a2 = b2; // ok + b2 = a2; // was error + ~~ +!!! error TS2322: Type 'CPromise' is not assignable to type 'CPromise'. +!!! error TS2322: Type 'Foo' is not assignable to type 'Bar'. + \ No newline at end of file diff --git a/tests/baselines/reference/recursiveTypeComparison2.errors.txt b/tests/baselines/reference/recursiveTypeComparison2.errors.txt index 5c1200ceec61f..71f337ad15fb4 100644 --- a/tests/baselines/reference/recursiveTypeComparison2.errors.txt +++ b/tests/baselines/reference/recursiveTypeComparison2.errors.txt @@ -1,7 +1,9 @@ tests/cases/compiler/recursiveTypeComparison2.ts(13,80): error TS2304: Cannot find name 'StateValue'. +tests/cases/compiler/recursiveTypeComparison2.ts(30,5): error TS2322: Type 'Bus<{}>' is not assignable to type 'Bus'. + Type '{}' is not assignable to type 'number'. -==== tests/cases/compiler/recursiveTypeComparison2.ts (1 errors) ==== +==== tests/cases/compiler/recursiveTypeComparison2.ts (2 errors) ==== // Before fix this would cause compiler to hang (#1170) declare module Bacon { @@ -33,4 +35,7 @@ tests/cases/compiler/recursiveTypeComparison2.ts(13,80): error TS2304: Cannot fi var Bus: new () => Bus; } - var stuck: Bacon.Bus = new Bacon.Bus(); \ No newline at end of file + var stuck: Bacon.Bus = new Bacon.Bus(); + ~~~~~ +!!! error TS2322: Type 'Bus<{}>' is not assignable to type 'Bus'. +!!! error TS2322: Type '{}' is not assignable to type 'number'. \ No newline at end of file diff --git a/tests/baselines/reference/subtypingWithCallSignatures2.types b/tests/baselines/reference/subtypingWithCallSignatures2.types index 8ce4b566b8651..86c65702b985c 100644 --- a/tests/baselines/reference/subtypingWithCallSignatures2.types +++ b/tests/baselines/reference/subtypingWithCallSignatures2.types @@ -681,14 +681,14 @@ var r9 = foo9(r9arg1); // any >r9arg1 : (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U var r9a = [r9arg1, r9arg2]; ->r9a : ((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U)[] ->[r9arg1, r9arg2] : ((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U)[] +>r9a : (((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] +>[r9arg1, r9arg2] : (((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] >r9arg1 : (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U >r9arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived var r9b = [r9arg2, r9arg1]; ->r9b : ((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U)[] ->[r9arg2, r9arg1] : ((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U)[] +>r9b : (((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] +>[r9arg2, r9arg1] : (((x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U) | ((x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived))[] >r9arg2 : (x: (arg: Base) => Derived, y: (arg2: Base) => Derived) => (r: Base) => Derived >r9arg1 : (x: (arg: T) => U, y: (arg2: { foo: string; bing: number; }) => U) => (r: T) => U diff --git a/tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts b/tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts new file mode 100644 index 0000000000000..4f3e7ecda0d66 --- /dev/null +++ b/tests/cases/conformance/types/typeRelationships/assignmentCompatibility/covariantCallbacks.ts @@ -0,0 +1,73 @@ +// @target: es2015 +// @strict: true + +// Test that callback parameters are related covariantly + +interface P { + then(cb: (value: T) => void): void; +}; + +interface A { a: string } +interface B extends A { b: string } + +function f1(a: P, b: P) { + a = b; + b = a; // Error +} + +function f2(a: Promise, b: Promise) { + a = b; + b = a; // Error +} + +interface AList1 { + forEach(cb: (item: A) => void): void; +} + +interface BList1 { + forEach(cb: (item: B) => void): void; +} + +function f11(a: AList1, b: BList1) { + a = b; + b = a; // Error +} + +interface AList2 { + forEach(cb: (item: A) => boolean): void; +} + +interface BList2 { + forEach(cb: (item: A) => void): void; +} + +function f12(a: AList2, b: BList2) { + a = b; + b = a; // Error +} + +interface AList3 { + forEach(cb: (item: A) => void): void; +} + +interface BList3 { + forEach(cb: (item: A, context: any) => void): void; +} + +function f13(a: AList3, b: BList3) { + a = b; + b = a; // Error +} + +interface AList4 { + forEach(cb: (item: A) => A): void; +} + +interface BList4 { + forEach(cb: (item: B) => B): void; +} + +function f14(a: AList4, b: BList4) { + a = b; + b = a; // Error +}