forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassignmentCompatFunctionsWithOptionalArgs.types
More file actions
69 lines (63 loc) · 2.12 KB
/
assignmentCompatFunctionsWithOptionalArgs.types
File metadata and controls
69 lines (63 loc) · 2.12 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//// [tests/cases/compiler/assignmentCompatFunctionsWithOptionalArgs.ts] ////
=== assignmentCompatFunctionsWithOptionalArgs.ts ===
function foo(x: { id: number; name?: string; }): void;
>foo : (x: { id: number; name?: string; }) => void
> : ^ ^^ ^^^^^
>x : { id: number; name?: string | undefined; }
> : ^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>id : number
> : ^^^^^^
>name : string | undefined
> : ^^^^^^^^^^^^^^^^^^
foo({ id: 1234 }); // Ok
>foo({ id: 1234 }) : void
> : ^^^^
>foo : (x: { id: number; name?: string; }) => void
> : ^ ^^ ^^^^^
>{ id: 1234 } : { id: number; }
> : ^^^^^^^^^^^^^^^
>id : number
> : ^^^^^^
>1234 : 1234
> : ^^^^
foo({ id: 1234, name: "hello" }); // Ok
>foo({ id: 1234, name: "hello" }) : void
> : ^^^^
>foo : (x: { id: number; name?: string; }) => void
> : ^ ^^ ^^^^^
>{ id: 1234, name: "hello" } : { id: number; name: string; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>id : number
> : ^^^^^^
>1234 : 1234
> : ^^^^
>name : string
> : ^^^^^^
>"hello" : "hello"
> : ^^^^^^^
foo({ id: 1234, name: false }); // Error, name of wrong type
>foo({ id: 1234, name: false }) : void
> : ^^^^
>foo : (x: { id: number; name?: string; }) => void
> : ^ ^^ ^^^^^
>{ id: 1234, name: false } : { id: number; name: boolean; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>id : number
> : ^^^^^^
>1234 : 1234
> : ^^^^
>name : boolean
> : ^^^^^^^
>false : false
> : ^^^^^
foo({ name: "hello" }); // Error, id required but missing
>foo({ name: "hello" }) : void
> : ^^^^
>foo : (x: { id: number; name?: string; }) => void
> : ^ ^^ ^^^^^
>{ name: "hello" } : { name: string; }
> : ^^^^^^^^^^^^^^^^^
>name : string
> : ^^^^^^
>"hello" : "hello"
> : ^^^^^^^