mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 12:51:30 -05:00
Test:excess property checks--discriminated unions
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
tests/cases/compiler/discriminatedUnionErrorMessage.ts(8,5): error TS2322: Type '{ kind: "sq"; x: number; y: number; }' is not assignable to type 'Shape'.
|
||||
Type '{ kind: "sq"; x: number; y: number; }' is not assignable to type 'Square'.
|
||||
Property 'size' is missing in type '{ kind: "sq"; x: number; y: number; }'.
|
||||
tests/cases/compiler/discriminatedUnionErrorMessage.ts(10,5): error TS2322: Type '{ kind: "sq"; x: number; y: number; }' is not assignable to type 'Shape'.
|
||||
Object literal may only specify known properties, and 'x' does not exist in type 'Square'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/discriminatedUnionErrorMessage.ts (1 errors) ====
|
||||
@@ -12,12 +11,11 @@ tests/cases/compiler/discriminatedUnionErrorMessage.ts(8,5): error TS2322: Type
|
||||
| Rectangle
|
||||
| Circle;
|
||||
let shape: Shape = {
|
||||
~~~~~
|
||||
!!! error TS2322: Type '{ kind: "sq"; x: number; y: number; }' is not assignable to type 'Shape'.
|
||||
!!! error TS2322: Type '{ kind: "sq"; x: number; y: number; }' is not assignable to type 'Square'.
|
||||
!!! error TS2322: Property 'size' is missing in type '{ kind: "sq"; x: number; y: number; }'.
|
||||
kind: "sq",
|
||||
x: 12,
|
||||
~~~~~
|
||||
!!! error TS2322: Type '{ kind: "sq"; x: number; y: number; }' is not assignable to type 'Shape'.
|
||||
!!! error TS2322: Object literal may only specify known properties, and 'x' does not exist in type 'Square'.
|
||||
y: 13,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
tests/cases/compiler/excessPropertyCheckWithUnions.ts(10,30): error TS2322: Type '{ tag: "T"; a1: string; }' is not assignable to type 'ADT'.
|
||||
Object literal may only specify known properties, and 'a1' does not exist in type '{ tag: "T"; }'.
|
||||
tests/cases/compiler/excessPropertyCheckWithUnions.ts(11,21): error TS2322: Type '{ tag: "A"; d20: 12; }' is not assignable to type 'ADT'.
|
||||
Object literal may only specify known properties, and 'd20' does not exist in type '{ tag: "A"; a1: string; }'.
|
||||
tests/cases/compiler/excessPropertyCheckWithUnions.ts(12,1): error TS2322: Type '{ tag: "D"; }' is not assignable to type 'ADT'.
|
||||
Type '{ tag: "D"; }' is not assignable to type '{ tag: "D"; d20: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20; }'.
|
||||
Property 'd20' is missing in type '{ tag: "D"; }'.
|
||||
|
||||
|
||||
==== tests/cases/compiler/excessPropertyCheckWithUnions.ts (3 errors) ====
|
||||
type ADT = {
|
||||
tag: "A",
|
||||
a1: string
|
||||
} | {
|
||||
tag: "D",
|
||||
d20: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20
|
||||
} | {
|
||||
tag: "T",
|
||||
}
|
||||
let wrong: ADT = { tag: "T", a1: "extra" }
|
||||
~~~~~~~~~~~
|
||||
!!! error TS2322: Type '{ tag: "T"; a1: string; }' is not assignable to type 'ADT'.
|
||||
!!! error TS2322: Object literal may only specify known properties, and 'a1' does not exist in type '{ tag: "T"; }'.
|
||||
wrong = { tag: "A", d20: 12 }
|
||||
~~~~~~~
|
||||
!!! error TS2322: Type '{ tag: "A"; d20: 12; }' is not assignable to type 'ADT'.
|
||||
!!! error TS2322: Object literal may only specify known properties, and 'd20' does not exist in type '{ tag: "A"; a1: string; }'.
|
||||
wrong = { tag: "D" }
|
||||
~~~~~
|
||||
!!! error TS2322: Type '{ tag: "D"; }' is not assignable to type 'ADT'.
|
||||
!!! error TS2322: Type '{ tag: "D"; }' is not assignable to type '{ tag: "D"; d20: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20; }'.
|
||||
!!! error TS2322: Property 'd20' is missing in type '{ tag: "D"; }'.
|
||||
|
||||
19
tests/baselines/reference/excessPropertyCheckWithUnions.js
Normal file
19
tests/baselines/reference/excessPropertyCheckWithUnions.js
Normal file
@@ -0,0 +1,19 @@
|
||||
//// [excessPropertyCheckWithUnions.ts]
|
||||
type ADT = {
|
||||
tag: "A",
|
||||
a1: string
|
||||
} | {
|
||||
tag: "D",
|
||||
d20: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20
|
||||
} | {
|
||||
tag: "T",
|
||||
}
|
||||
let wrong: ADT = { tag: "T", a1: "extra" }
|
||||
wrong = { tag: "A", d20: 12 }
|
||||
wrong = { tag: "D" }
|
||||
|
||||
|
||||
//// [excessPropertyCheckWithUnions.js]
|
||||
var wrong = { tag: "T", a1: "extra" };
|
||||
wrong = { tag: "A", d20: 12 };
|
||||
wrong = { tag: "D" };
|
||||
12
tests/cases/compiler/excessPropertyCheckWithUnions.ts
Normal file
12
tests/cases/compiler/excessPropertyCheckWithUnions.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
type ADT = {
|
||||
tag: "A",
|
||||
a1: string
|
||||
} | {
|
||||
tag: "D",
|
||||
d20: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20
|
||||
} | {
|
||||
tag: "T",
|
||||
}
|
||||
let wrong: ADT = { tag: "T", a1: "extra" }
|
||||
wrong = { tag: "A", d20: 12 }
|
||||
wrong = { tag: "D" }
|
||||
Reference in New Issue
Block a user