diff --git a/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates01.errors.txt b/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates01.errors.txt new file mode 100644 index 00000000000..035fbc36c14 --- /dev/null +++ b/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates01.errors.txt @@ -0,0 +1,39 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatForSignaturesWithTypePredicates01.ts(21,1): error TS2322: Type '(x: any) => x is B' is not assignable to type '(x: any) => x is A'. + Type predicate 'x is B' is not assignable to 'x is A'. + Type 'B' is not assignable to type 'A'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatForSignaturesWithTypePredicates01.ts(22,1): error TS2322: Type '(x: any) => x is A' is not assignable to type '(x: any) => x is B'. + Type predicate 'x is A' is not assignable to 'x is B'. + Type 'A' is not assignable to type 'B'. + + +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatForSignaturesWithTypePredicates01.ts (2 errors) ==== + + class A { + private a; + } + + class B extends A { + private b; + } + + function isA(x: any): x is A { + return x instanceof A; + } + + function isB(x: any): x is B { + return x instanceof B; + } + + let myIsA = isA; + let myIsB = isB; + + myIsA = myIsB; + ~~~~~ +!!! error TS2322: Type '(x: any) => x is B' is not assignable to type '(x: any) => x is A'. +!!! error TS2322: Type predicate 'x is B' is not assignable to 'x is A'. +!!! error TS2322: Type 'B' is not assignable to type 'A'. + myIsB = myIsA; + ~~~~~ +!!! error TS2322: Type '(x: any) => x is A' is not assignable to type '(x: any) => x is B'. +!!! error TS2322: Type predicate 'x is A' is not assignable to 'x is B'. +!!! error TS2322: Type 'A' is not assignable to type 'B'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates01.js b/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates01.js new file mode 100644 index 00000000000..51ea3d9c714 --- /dev/null +++ b/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates01.js @@ -0,0 +1,65 @@ +//// [assignmentCompatForSignaturesWithTypePredicates01.ts] + +class A { + private a; +} + +class B extends A { + private b; +} + +function isA(x: any): x is A { + return x instanceof A; +} + +function isB(x: any): x is B { + return x instanceof B; +} + +let myIsA = isA; +let myIsB = isB; + +myIsA = myIsB; +myIsB = myIsA; + +//// [assignmentCompatForSignaturesWithTypePredicates01.js] +var __extends = (this && this.__extends) || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +}; +var A = (function () { + function A() { + } + return A; +})(); +var B = (function (_super) { + __extends(B, _super); + function B() { + _super.apply(this, arguments); + } + return B; +})(A); +function isA(x) { + return x instanceof A; +} +function isB(x) { + return x instanceof B; +} +var myIsA = isA; +var myIsB = isB; +myIsA = myIsB; +myIsB = myIsA; + + +//// [assignmentCompatForSignaturesWithTypePredicates01.d.ts] +declare class A { + private a; +} +declare class B extends A { + private b; +} +declare function isA(x: any): x is A; +declare function isB(x: any): x is B; +declare let myIsA: typeof isA; +declare let myIsB: typeof isB; diff --git a/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates02.errors.txt b/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates02.errors.txt new file mode 100644 index 00000000000..8079be20a71 --- /dev/null +++ b/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates02.errors.txt @@ -0,0 +1,38 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatForSignaturesWithTypePredicates02.ts(11,25): error TS2304: Cannot find name 'B'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatForSignaturesWithTypePredicates02.ts(17,1): error TS2322: Type '(x: any) => x is any' is not assignable to type '(x: any) => x is A'. + Type predicate 'x is any' is not assignable to 'x is A'. + Type 'any' is not assignable to type 'A'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatForSignaturesWithTypePredicates02.ts(18,1): error TS2322: Type '(x: any) => x is A' is not assignable to type '(x: any) => x is any'. + Type predicate 'x is A' is not assignable to 'x is any'. + Type 'A' is not assignable to type 'any'. + + +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatForSignaturesWithTypePredicates02.ts (3 errors) ==== + + class A { + private a; + } + + function isA(x: any): x is A { + return x instanceof A; + } + + function isAny(x: any): x is any { + return x instanceof B; + ~ +!!! error TS2304: Cannot find name 'B'. + } + + let myIsA = isA; + let myIsAny = isAny; + + myIsA = myIsAny; + ~~~~~ +!!! error TS2322: Type '(x: any) => x is any' is not assignable to type '(x: any) => x is A'. +!!! error TS2322: Type predicate 'x is any' is not assignable to 'x is A'. +!!! error TS2322: Type 'any' is not assignable to type 'A'. + myIsAny = myIsA; + ~~~~~~~ +!!! error TS2322: Type '(x: any) => x is A' is not assignable to type '(x: any) => x is any'. +!!! error TS2322: Type predicate 'x is A' is not assignable to 'x is any'. +!!! error TS2322: Type 'A' is not assignable to type 'any'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates02.js b/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates02.js new file mode 100644 index 00000000000..cdd7fbe0f96 --- /dev/null +++ b/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates02.js @@ -0,0 +1,46 @@ +//// [assignmentCompatForSignaturesWithTypePredicates02.ts] + +class A { + private a; +} + +function isA(x: any): x is A { + return x instanceof A; +} + +function isAny(x: any): x is any { + return x instanceof B; +} + +let myIsA = isA; +let myIsAny = isAny; + +myIsA = myIsAny; +myIsAny = myIsA; + +//// [assignmentCompatForSignaturesWithTypePredicates02.js] +var A = (function () { + function A() { + } + return A; +})(); +function isA(x) { + return x instanceof A; +} +function isAny(x) { + return x instanceof B; +} +var myIsA = isA; +var myIsAny = isAny; +myIsA = myIsAny; +myIsAny = myIsA; + + +//// [assignmentCompatForSignaturesWithTypePredicates02.d.ts] +declare class A { + private a; +} +declare function isA(x: any): x is A; +declare function isAny(x: any): x is any; +declare let myIsA: typeof isA; +declare let myIsAny: typeof isAny; diff --git a/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates03.errors.txt b/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates03.errors.txt new file mode 100644 index 00000000000..bfb94ff40d5 --- /dev/null +++ b/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates03.errors.txt @@ -0,0 +1,38 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatForSignaturesWithTypePredicates03.ts(20,1): error TS2322: Type '(x: any) => x is B' is not assignable to type '(x: any) => x is A'. + Type predicate 'x is B' is not assignable to 'x is A'. + Type 'B' is not assignable to type 'A'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatForSignaturesWithTypePredicates03.ts(21,1): error TS2322: Type '(x: any) => x is A' is not assignable to type '(x: any) => x is B'. + Type predicate 'x is A' is not assignable to 'x is B'. + Type 'A' is not assignable to type 'B'. + + +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatForSignaturesWithTypePredicates03.ts (2 errors) ==== + + interface A { + a?; + } + + interface B { + } + + function isA(x: any): x is A { + return !!(x).a; + } + + function isB(x: any): x is B { + return !!isA(x); + } + + let myIsA = isA; + let myIsAny = isB; + + myIsA = myIsAny; + ~~~~~ +!!! error TS2322: Type '(x: any) => x is B' is not assignable to type '(x: any) => x is A'. +!!! error TS2322: Type predicate 'x is B' is not assignable to 'x is A'. +!!! error TS2322: Type 'B' is not assignable to type 'A'. + myIsAny = myIsA; + ~~~~~~~ +!!! error TS2322: Type '(x: any) => x is A' is not assignable to type '(x: any) => x is B'. +!!! error TS2322: Type predicate 'x is A' is not assignable to 'x is B'. +!!! error TS2322: Type 'A' is not assignable to type 'B'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates03.js b/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates03.js new file mode 100644 index 00000000000..10f9ce61e95 --- /dev/null +++ b/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates03.js @@ -0,0 +1,46 @@ +//// [assignmentCompatForSignaturesWithTypePredicates03.ts] + +interface A { + a?; +} + +interface B { +} + +function isA(x: any): x is A { + return !!(x).a; +} + +function isB(x: any): x is B { + return !!isA(x); +} + +let myIsA = isA; +let myIsAny = isB; + +myIsA = myIsAny; +myIsAny = myIsA; + +//// [assignmentCompatForSignaturesWithTypePredicates03.js] +function isA(x) { + return !!x.a; +} +function isB(x) { + return !!isA(x); +} +var myIsA = isA; +var myIsAny = isB; +myIsA = myIsAny; +myIsAny = myIsA; + + +//// [assignmentCompatForSignaturesWithTypePredicates03.d.ts] +interface A { + a?: any; +} +interface B { +} +declare function isA(x: any): x is A; +declare function isB(x: any): x is B; +declare let myIsA: typeof isA; +declare let myIsAny: typeof isB; diff --git a/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates04.errors.txt b/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates04.errors.txt new file mode 100644 index 00000000000..16abe2efeaf --- /dev/null +++ b/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates04.errors.txt @@ -0,0 +1,43 @@ +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatForSignaturesWithTypePredicates04.ts(25,1): error TS2322: Type '(x: any) => x is E' is not assignable to type '(x: any) => x is number'. + Type predicate 'x is E' is not assignable to 'x is number'. + Type 'E' is not assignable to type 'number'. +tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatForSignaturesWithTypePredicates04.ts(26,1): error TS2322: Type '(x: any) => x is number' is not assignable to type '(x: any) => x is E'. + Type predicate 'x is number' is not assignable to 'x is E'. + Type 'number' is not assignable to type 'E'. + + +==== tests/cases/conformance/types/typeRelationships/assignmentCompatibility/assignmentCompatForSignaturesWithTypePredicates04.ts (2 errors) ==== + + enum E { + A = 1, + B = 2, + C = 3, + } + + function isA(x: any): x is number { + return typeof x === "number"; + } + + function isB(x: any): x is E { + switch (x) { + case E.A: + case E.B: + case E.C: + return true; + } + return false; + } + + let myIsA = isA; + let myIsB = isB; + + myIsA = myIsB; + ~~~~~ +!!! error TS2322: Type '(x: any) => x is E' is not assignable to type '(x: any) => x is number'. +!!! error TS2322: Type predicate 'x is E' is not assignable to 'x is number'. +!!! error TS2322: Type 'E' is not assignable to type 'number'. + myIsB = myIsA; + ~~~~~ +!!! error TS2322: Type '(x: any) => x is number' is not assignable to type '(x: any) => x is E'. +!!! error TS2322: Type predicate 'x is number' is not assignable to 'x is E'. +!!! error TS2322: Type 'number' is not assignable to type 'E'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates04.js b/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates04.js new file mode 100644 index 00000000000..dfb70f2ee56 --- /dev/null +++ b/tests/baselines/reference/assignmentCompatForSignaturesWithTypePredicates04.js @@ -0,0 +1,63 @@ +//// [assignmentCompatForSignaturesWithTypePredicates04.ts] + +enum E { + A = 1, + B = 2, + C = 3, +} + +function isA(x: any): x is number { + return typeof x === "number"; +} + +function isB(x: any): x is E { + switch (x) { + case E.A: + case E.B: + case E.C: + return true; + } + return false; +} + +let myIsA = isA; +let myIsB = isB; + +myIsA = myIsB; +myIsB = myIsA; + +//// [assignmentCompatForSignaturesWithTypePredicates04.js] +var E; +(function (E) { + E[E["A"] = 1] = "A"; + E[E["B"] = 2] = "B"; + E[E["C"] = 3] = "C"; +})(E || (E = {})); +function isA(x) { + return typeof x === "number"; +} +function isB(x) { + switch (x) { + case E.A: + case E.B: + case E.C: + return true; + } + return false; +} +var myIsA = isA; +var myIsB = isB; +myIsA = myIsB; +myIsB = myIsA; + + +//// [assignmentCompatForSignaturesWithTypePredicates04.d.ts] +declare enum E { + A = 1, + B = 2, + C = 3, +} +declare function isA(x: any): x is number; +declare function isB(x: any): x is E; +declare let myIsA: typeof isA; +declare let myIsB: typeof isB;