File: discriminateWithMissingProperty.types

package info (click to toggle)
node-typescript 5.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 497,488 kB
  • sloc: javascript: 2,107,274; makefile: 6; sh: 1
file content (40 lines) | stat: -rw-r--r-- 990 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//// [tests/cases/compiler/discriminateWithMissingProperty.ts] ////

=== discriminateWithMissingProperty.ts ===
type Arg = {
>Arg : { mode: "numeric"; data: number; } | { mode: "alphabetic"; data: string; } | { data: string | Uint8Array; }

    mode: "numeric",
>mode : "numeric"

    data: number,
>data : number

} | {
    mode: "alphabetic",
>mode : "alphabetic"

    data: string,
>data : string

} | {
    data: string | Uint8Array;
>data : string | Uint8Array
}

declare function foo(arg: Arg): void;
>foo : (arg: Arg) => void
>arg : Arg

foo({ mode: "numeric", data: new Uint8Array([30]) }); // Should error
>foo({ mode: "numeric", data: new Uint8Array([30]) }) : void
>foo : (arg: Arg) => void
>{ mode: "numeric", data: new Uint8Array([30]) } : { mode: "numeric"; data: Uint8Array; }
>mode : "numeric"
>"numeric" : "numeric"
>data : Uint8Array
>new Uint8Array([30]) : Uint8Array
>Uint8Array : Uint8ArrayConstructor
>[30] : number[]
>30 : 30