Add difference type error tests and update baselines
This commit is contained in:
parent
bd24964b9c
commit
813e2352dc
|
@ -13,9 +13,9 @@ let nope: string - string;
|
|||
let nope2: 'a' | 'b' - string;
|
||||
let nope3: string - 'a' | 'b';
|
||||
|
||||
// TODO: Require a constraint of extends string?
|
||||
// or keyof X? Check the mapped type code to decide what to do
|
||||
function f<T,U> (t: T, u: U) {
|
||||
type Abcd = { a; b; c; d }
|
||||
|
||||
function f<T,U extends keyof Abcd> (t: T, u: U) {
|
||||
let tsubu: T - U;
|
||||
return tsubu;
|
||||
}
|
||||
|
@ -33,8 +33,6 @@ var empty;
|
|||
var nope;
|
||||
var nope2;
|
||||
var nope3;
|
||||
// TODO: Require a constraint of extends string?
|
||||
// or keyof X? Check the mapped type code to decide what to do
|
||||
function f(t, u) {
|
||||
var tsubu;
|
||||
return tsubu;
|
||||
|
|
|
@ -44,15 +44,21 @@ let nope2: 'a' | 'b' - string;
|
|||
let nope3: string - 'a' | 'b';
|
||||
>nope3 : Symbol(nope3, Decl(differenceType.ts, 12, 3))
|
||||
|
||||
// TODO: Require a constraint of extends string?
|
||||
// or keyof X? Check the mapped type code to decide what to do
|
||||
function f<T,U> (t: T, u: U) {
|
||||
>f : Symbol(f, Decl(differenceType.ts, 12, 30))
|
||||
type Abcd = { a; b; c; d }
|
||||
>Abcd : Symbol(Abcd, Decl(differenceType.ts, 12, 30))
|
||||
>a : Symbol(a, Decl(differenceType.ts, 14, 13))
|
||||
>b : Symbol(b, Decl(differenceType.ts, 14, 16))
|
||||
>c : Symbol(c, Decl(differenceType.ts, 14, 19))
|
||||
>d : Symbol(d, Decl(differenceType.ts, 14, 22))
|
||||
|
||||
function f<T,U extends keyof Abcd> (t: T, u: U) {
|
||||
>f : Symbol(f, Decl(differenceType.ts, 14, 26))
|
||||
>T : Symbol(T, Decl(differenceType.ts, 16, 11))
|
||||
>U : Symbol(U, Decl(differenceType.ts, 16, 13))
|
||||
>t : Symbol(t, Decl(differenceType.ts, 16, 17))
|
||||
>Abcd : Symbol(Abcd, Decl(differenceType.ts, 12, 30))
|
||||
>t : Symbol(t, Decl(differenceType.ts, 16, 36))
|
||||
>T : Symbol(T, Decl(differenceType.ts, 16, 11))
|
||||
>u : Symbol(u, Decl(differenceType.ts, 16, 22))
|
||||
>u : Symbol(u, Decl(differenceType.ts, 16, 41))
|
||||
>U : Symbol(U, Decl(differenceType.ts, 16, 13))
|
||||
|
||||
let tsubu: T - U;
|
||||
|
@ -66,5 +72,5 @@ function f<T,U> (t: T, u: U) {
|
|||
|
||||
const x = f<'a' | 'b', 'b' | 'd'>('a', 'b');
|
||||
>x : Symbol(x, Decl(differenceType.ts, 21, 5))
|
||||
>f : Symbol(f, Decl(differenceType.ts, 12, 30))
|
||||
>f : Symbol(f, Decl(differenceType.ts, 14, 26))
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ type C = 'c';
|
|||
>C : "c"
|
||||
|
||||
type AB = A | B;
|
||||
>AB : AB
|
||||
>AB : "a" | "b"
|
||||
>A : "a"
|
||||
>B : "b"
|
||||
|
||||
|
@ -19,7 +19,7 @@ let nothing: A - 'a';
|
|||
|
||||
let none: AB - 'a' | 'b';
|
||||
>none : never
|
||||
>AB : AB
|
||||
>AB : "a" | "b"
|
||||
|
||||
let over: 'a' - 'a' | 'b';
|
||||
>over : never
|
||||
|
@ -32,8 +32,8 @@ let partial: 'a' | 'b' - 'b' | 'd';
|
|||
|
||||
let empty: AB - AB;
|
||||
>empty : never
|
||||
>AB : AB
|
||||
>AB : AB
|
||||
>AB : "a" | "b"
|
||||
>AB : "a" | "b"
|
||||
|
||||
let nope: string - string;
|
||||
>nope : never
|
||||
|
@ -44,12 +44,18 @@ let nope2: 'a' | 'b' - string;
|
|||
let nope3: string - 'a' | 'b';
|
||||
>nope3 : string
|
||||
|
||||
// TODO: Require a constraint of extends string?
|
||||
// or keyof X? Check the mapped type code to decide what to do
|
||||
function f<T,U> (t: T, u: U) {
|
||||
>f : <T, U>(t: T, u: U) => T - U
|
||||
type Abcd = { a; b; c; d }
|
||||
>Abcd : Abcd
|
||||
>a : any
|
||||
>b : any
|
||||
>c : any
|
||||
>d : any
|
||||
|
||||
function f<T,U extends keyof Abcd> (t: T, u: U) {
|
||||
>f : <T, U extends "a" | "b" | "d" | "c">(t: T, u: U) => T - U
|
||||
>T : T
|
||||
>U : U
|
||||
>Abcd : Abcd
|
||||
>t : T
|
||||
>T : T
|
||||
>u : U
|
||||
|
@ -67,7 +73,7 @@ function f<T,U> (t: T, u: U) {
|
|||
const x = f<'a' | 'b', 'b' | 'd'>('a', 'b');
|
||||
>x : "a"
|
||||
>f<'a' | 'b', 'b' | 'd'>('a', 'b') : "a"
|
||||
>f : <T, U>(t: T, u: U) => T - U
|
||||
>f : <T, U extends "a" | "b" | "d" | "c">(t: T, u: U) => T - U
|
||||
>'a' : "a"
|
||||
>'b' : "b"
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
tests/cases/conformance/types/rest/differenceTypeAssignability.ts(14,5): error TS2322: Type 'T - V' is not assignable to type 'T - U'.
|
||||
Type 'V' is not assignable to type 'U'.
|
||||
Type 'string' is not assignable to type 'U'.
|
||||
tests/cases/conformance/types/rest/differenceTypeAssignability.ts(15,5): error TS2322: Type 'U' is not assignable to type 'T'.
|
||||
Type '"u"' is not assignable to type 'T'.
|
||||
tests/cases/conformance/types/rest/differenceTypeAssignability.ts(26,5): error TS2322: Type 'T - "c"' is not assignable to type 'T - "a"'.
|
||||
Type '"c"' is not assignable to type '"a"'.
|
||||
tests/cases/conformance/types/rest/differenceTypeAssignability.ts(27,5): error TS2322: Type 'T - AB' is not assignable to type 'T - "a"'.
|
||||
|
@ -8,20 +10,23 @@ tests/cases/conformance/types/rest/differenceTypeAssignability.ts(27,5): error T
|
|||
Type '"b"' is not assignable to type '"a"'.
|
||||
tests/cases/conformance/types/rest/differenceTypeAssignability.ts(28,5): error TS2322: Type 'T - "a"' is not assignable to type 'T'.
|
||||
tests/cases/conformance/types/rest/differenceTypeAssignability.ts(29,5): error TS2322: Type 'U' is not assignable to type 'T'.
|
||||
Type '"u"' is not assignable to type 'T'.
|
||||
tests/cases/conformance/types/rest/differenceTypeAssignability.ts(38,5): error TS2322: Type '{ a: any; }' is not assignable to type '{ a: any; b: any; }'.
|
||||
Property 'b' is missing in type '{ a: any; }'.
|
||||
tests/cases/conformance/types/rest/differenceTypeAssignability.ts(39,5): error TS2322: Type '{ a: any; b: any; } - T' is not assignable to type '{ a: any; b: any; } - U'.
|
||||
Type 'T' is not assignable to type 'U'.
|
||||
Type '"x" | "y" | "z"' is not assignable to type 'U'.
|
||||
Type '"x"' is not assignable to type 'U'.
|
||||
tests/cases/conformance/types/rest/differenceTypeAssignability.ts(40,5): error TS2322: Type '{ a: any; c: any; }' is not assignable to type '{ a: any; b: any; }'.
|
||||
Property 'b' is missing in type '{ a: any; c: any; }'.
|
||||
tests/cases/conformance/types/rest/differenceTypeAssignability.ts(42,5): error TS2322: Type '{ a: any; }' is not assignable to type 'T'.
|
||||
tests/cases/conformance/types/rest/differenceTypeAssignability.ts(43,5): error TS2322: Type 'T - U' is not assignable to type 'T - "a"'.
|
||||
Type 'U' is not assignable to type '"a"'.
|
||||
Type '"u"' is not assignable to type '"a"'.
|
||||
tests/cases/conformance/types/rest/differenceTypeAssignability.ts(44,5): error TS2322: Type 'T - "a"' is not assignable to type 'T - U'.
|
||||
Type '"a"' is not assignable to type 'U'.
|
||||
tests/cases/conformance/types/rest/differenceTypeAssignability.ts(47,5): error TS2322: Type 'BN' is not assignable to type 'T - "a"'.
|
||||
tests/cases/conformance/types/rest/differenceTypeAssignability.ts(48,5): error TS2322: Type 'T - "a"' is not assignable to type 'BN'.
|
||||
Property 'b' is missing in type '{}'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/rest/differenceTypeAssignability.ts (14 errors) ====
|
||||
|
@ -31,7 +36,7 @@ tests/cases/conformance/types/rest/differenceTypeAssignability.ts(48,5): error T
|
|||
type AB = A | B;
|
||||
type AC = A | C;
|
||||
type BN = { b: number };
|
||||
function f<T,U, V> (t: T, u: U, v: V) {
|
||||
function f<T extends 'x' | 'y' | 'z', U extends 'u', V extends string> (t: T, u: U, v: V) {
|
||||
let t_u: T - U;
|
||||
let t_v: T - V;
|
||||
let u_t: U - T;
|
||||
|
@ -42,9 +47,11 @@ tests/cases/conformance/types/rest/differenceTypeAssignability.ts(48,5): error T
|
|||
~~~
|
||||
!!! error TS2322: Type 'T - V' is not assignable to type 'T - U'.
|
||||
!!! error TS2322: Type 'V' is not assignable to type 'U'.
|
||||
!!! error TS2322: Type 'string' is not assignable to type 'U'.
|
||||
t_u = u_t; // error
|
||||
~~~
|
||||
!!! error TS2322: Type 'U' is not assignable to type 'T'.
|
||||
!!! error TS2322: Type '"u"' is not assignable to type 'T'.
|
||||
|
||||
var t_a: T - A;
|
||||
var t_c: T - C;
|
||||
|
@ -70,6 +77,7 @@ tests/cases/conformance/types/rest/differenceTypeAssignability.ts(48,5): error T
|
|||
t_a = u_a; // error
|
||||
~~~
|
||||
!!! error TS2322: Type 'U' is not assignable to type 'T'.
|
||||
!!! error TS2322: Type '"u"' is not assignable to type 'T'.
|
||||
|
||||
var ab_u: { a, b } - U;
|
||||
var ab_t: { a, b } - T;
|
||||
|
@ -86,6 +94,8 @@ tests/cases/conformance/types/rest/differenceTypeAssignability.ts(48,5): error T
|
|||
~~~~
|
||||
!!! error TS2322: Type '{ a: any; b: any; } - T' is not assignable to type '{ a: any; b: any; } - U'.
|
||||
!!! error TS2322: Type 'T' is not assignable to type 'U'.
|
||||
!!! error TS2322: Type '"x" | "y" | "z"' is not assignable to type 'U'.
|
||||
!!! error TS2322: Type '"x"' is not assignable to type 'U'.
|
||||
ab_t = ac_t // error
|
||||
~~~~
|
||||
!!! error TS2322: Type '{ a: any; c: any; }' is not assignable to type '{ a: any; b: any; }'.
|
||||
|
@ -98,6 +108,7 @@ tests/cases/conformance/types/rest/differenceTypeAssignability.ts(48,5): error T
|
|||
~~~
|
||||
!!! error TS2322: Type 'T - U' is not assignable to type 'T - "a"'.
|
||||
!!! error TS2322: Type 'U' is not assignable to type '"a"'.
|
||||
!!! error TS2322: Type '"u"' is not assignable to type '"a"'.
|
||||
t_u = t_a; // error, let T contain property a and U not. Then T-a has no a, but T-U does.
|
||||
~~~
|
||||
!!! error TS2322: Type 'T - "a"' is not assignable to type 'T - U'.
|
||||
|
@ -110,6 +121,5 @@ tests/cases/conformance/types/rest/differenceTypeAssignability.ts(48,5): error T
|
|||
bn = t_a; // would be ok only if T extends BN
|
||||
~~
|
||||
!!! error TS2322: Type 'T - "a"' is not assignable to type 'BN'.
|
||||
!!! error TS2322: Property 'b' is missing in type '{}'.
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ type C = 'c';
|
|||
type AB = A | B;
|
||||
type AC = A | C;
|
||||
type BN = { b: number };
|
||||
function f<T,U, V> (t: T, u: U, v: V) {
|
||||
function f<T extends 'x' | 'y' | 'z', U extends 'u', V extends string> (t: T, u: U, v: V) {
|
||||
let t_u: T - U;
|
||||
let t_v: T - V;
|
||||
let u_t: U - T;
|
||||
|
|
45
tests/baselines/reference/differenceTypeNegative.errors.txt
Normal file
45
tests/baselines/reference/differenceTypeNegative.errors.txt
Normal file
|
@ -0,0 +1,45 @@
|
|||
tests/cases/conformance/types/rest/differenceTypeNegative.ts(3,17): error TS2705: The right side of a difference type must be a string or string literal union, or a type parameter constrained to one of these.
|
||||
tests/cases/conformance/types/rest/differenceTypeNegative.ts(4,17): error TS2705: The right side of a difference type must be a string or string literal union, or a type parameter constrained to one of these.
|
||||
tests/cases/conformance/types/rest/differenceTypeNegative.ts(5,17): error TS2705: The right side of a difference type must be a string or string literal union, or a type parameter constrained to one of these.
|
||||
tests/cases/conformance/types/rest/differenceTypeNegative.ts(6,17): error TS2705: The right side of a difference type must be a string or string literal union, or a type parameter constrained to one of these.
|
||||
tests/cases/conformance/types/rest/differenceTypeNegative.ts(8,21): error TS2705: The right side of a difference type must be a string or string literal union, or a type parameter constrained to one of these.
|
||||
tests/cases/conformance/types/rest/differenceTypeNegative.ts(9,21): error TS2705: The right side of a difference type must be a string or string literal union, or a type parameter constrained to one of these.
|
||||
tests/cases/conformance/types/rest/differenceTypeNegative.ts(10,21): error TS2705: The right side of a difference type must be a string or string literal union, or a type parameter constrained to one of these.
|
||||
tests/cases/conformance/types/rest/differenceTypeNegative.ts(11,21): error TS2705: The right side of a difference type must be a string or string literal union, or a type parameter constrained to one of these.
|
||||
tests/cases/conformance/types/rest/differenceTypeNegative.ts(12,21): error TS2705: The right side of a difference type must be a string or string literal union, or a type parameter constrained to one of these.
|
||||
|
||||
|
||||
==== tests/cases/conformance/types/rest/differenceTypeNegative.ts (9 errors) ====
|
||||
type Abc = { a; b; c }
|
||||
type Surprise = 'a' | 'b' | 12;
|
||||
let bad1: Abc - 12;
|
||||
~~
|
||||
!!! error TS2705: The right side of a difference type must be a string or string literal union, or a type parameter constrained to one of these.
|
||||
let bad2: Abc - Surprise;
|
||||
~~~~~~~~
|
||||
!!! error TS2705: The right side of a difference type must be a string or string literal union, or a type parameter constrained to one of these.
|
||||
let bad3: Abc - 'a' & 'b';
|
||||
~~~~~~~~~
|
||||
!!! error TS2705: The right side of a difference type must be a string or string literal union, or a type parameter constrained to one of these.
|
||||
let bad4: Abc - number;
|
||||
~~~~~~
|
||||
!!! error TS2705: The right side of a difference type must be a string or string literal union, or a type parameter constrained to one of these.
|
||||
function f<T, U extends 12, V extends Surprise, W extends 'a' & 'b', X extends number>(t: T) {
|
||||
let bad1: Abc - T;
|
||||
~
|
||||
!!! error TS2705: The right side of a difference type must be a string or string literal union, or a type parameter constrained to one of these.
|
||||
let bad2: Abc - 12;
|
||||
~~
|
||||
!!! error TS2705: The right side of a difference type must be a string or string literal union, or a type parameter constrained to one of these.
|
||||
let bad3: Abc - Surprise;
|
||||
~~~~~~~~
|
||||
!!! error TS2705: The right side of a difference type must be a string or string literal union, or a type parameter constrained to one of these.
|
||||
let bad4: Abc - 'a' & 'b';
|
||||
~~~~~~~~~
|
||||
!!! error TS2705: The right side of a difference type must be a string or string literal union, or a type parameter constrained to one of these.
|
||||
let bad5: Abc - number;
|
||||
~~~~~~
|
||||
!!! error TS2705: The right side of a difference type must be a string or string literal union, or a type parameter constrained to one of these.
|
||||
return bad1;
|
||||
}
|
||||
|
30
tests/baselines/reference/differenceTypeNegative.js
Normal file
30
tests/baselines/reference/differenceTypeNegative.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
//// [differenceTypeNegative.ts]
|
||||
type Abc = { a; b; c }
|
||||
type Surprise = 'a' | 'b' | 12;
|
||||
let bad1: Abc - 12;
|
||||
let bad2: Abc - Surprise;
|
||||
let bad3: Abc - 'a' & 'b';
|
||||
let bad4: Abc - number;
|
||||
function f<T, U extends 12, V extends Surprise, W extends 'a' & 'b', X extends number>(t: T) {
|
||||
let bad1: Abc - T;
|
||||
let bad2: Abc - 12;
|
||||
let bad3: Abc - Surprise;
|
||||
let bad4: Abc - 'a' & 'b';
|
||||
let bad5: Abc - number;
|
||||
return bad1;
|
||||
}
|
||||
|
||||
|
||||
//// [differenceTypeNegative.js]
|
||||
var bad1;
|
||||
var bad2;
|
||||
var bad3;
|
||||
var bad4;
|
||||
function f(t) {
|
||||
var bad1;
|
||||
var bad2;
|
||||
var bad3;
|
||||
var bad4;
|
||||
var bad5;
|
||||
return bad1;
|
||||
}
|
|
@ -1,13 +1,16 @@
|
|||
tests/cases/compiler/dontShowCompilerGeneratedMembers.ts(3,6): error TS1139: Type parameter declaration expected.
|
||||
tests/cases/compiler/dontShowCompilerGeneratedMembers.ts(3,7): error TS2705: The right side of a difference type must be a string or string literal union, or a type parameter constrained to one of these.
|
||||
tests/cases/compiler/dontShowCompilerGeneratedMembers.ts(4,1): error TS1110: Type expected.
|
||||
|
||||
|
||||
==== tests/cases/compiler/dontShowCompilerGeneratedMembers.ts (2 errors) ====
|
||||
==== tests/cases/compiler/dontShowCompilerGeneratedMembers.ts (3 errors) ====
|
||||
var f: {
|
||||
x: number;
|
||||
<-
|
||||
~
|
||||
!!! error TS1139: Type parameter declaration expected.
|
||||
|
||||
!!! error TS2705: The right side of a difference type must be a string or string literal union, or a type parameter constrained to one of these.
|
||||
};
|
||||
~
|
||||
!!! error TS1110: Type expected.
|
|
@ -12,9 +12,9 @@ let nope: string - string;
|
|||
let nope2: 'a' | 'b' - string;
|
||||
let nope3: string - 'a' | 'b';
|
||||
|
||||
// TODO: Require a constraint of extends string?
|
||||
// or keyof X? Check the mapped type code to decide what to do
|
||||
function f<T,U> (t: T, u: U) {
|
||||
type Abcd = { a; b; c; d }
|
||||
|
||||
function f<T,U extends keyof Abcd> (t: T, u: U) {
|
||||
let tsubu: T - U;
|
||||
return tsubu;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ type C = 'c';
|
|||
type AB = A | B;
|
||||
type AC = A | C;
|
||||
type BN = { b: number };
|
||||
function f<T,U, V> (t: T, u: U, v: V) {
|
||||
function f<T extends 'x' | 'y' | 'z', U extends 'u', V extends string> (t: T, u: U, v: V) {
|
||||
let t_u: T - U;
|
||||
let t_v: T - V;
|
||||
let u_t: U - T;
|
||||
|
|
14
tests/cases/conformance/types/rest/differenceTypeNegative.ts
Normal file
14
tests/cases/conformance/types/rest/differenceTypeNegative.ts
Normal file
|
@ -0,0 +1,14 @@
|
|||
type Abc = { a; b; c }
|
||||
type Surprise = 'a' | 'b' | 12;
|
||||
let bad1: Abc - 12;
|
||||
let bad2: Abc - Surprise;
|
||||
let bad3: Abc - 'a' & 'b';
|
||||
let bad4: Abc - number;
|
||||
function f<T, U extends 12, V extends Surprise, W extends 'a' & 'b', X extends number>(t: T) {
|
||||
let bad1: Abc - T;
|
||||
let bad2: Abc - 12;
|
||||
let bad3: Abc - Surprise;
|
||||
let bad4: Abc - 'a' & 'b';
|
||||
let bad5: Abc - number;
|
||||
return bad1;
|
||||
}
|
Loading…
Reference in a new issue