File: nestedTypeVariableInfersLiteral.types

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (86 lines) | stat: -rw-r--r-- 3,014 bytes parent folder | download | duplicates (4)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
=== tests/cases/compiler/nestedTypeVariableInfersLiteral.ts ===
// https://github.com/Microsoft/TypeScript/issues/19632
declare function direct<A extends string>(a: A | A[]): Record<A, string>
>direct : <A extends string>(a: A | A[]) => Record<A, string>
>a : A | A[]

declare function nested<A extends string>(a: { fields: A }): Record<A, string>
>nested : <A extends string>(a: {    fields: A;}) => Record<A, string>
>a : { fields: A; }
>fields : A

declare function nestedUnion<A extends string>(a: { fields: A | A[] }): Record<A, string>
>nestedUnion : <A extends string>(a: {    fields: A | A[];}) => Record<A, string>
>a : { fields: A | A[]; }
>fields : A | A[]

const directUnionSingle = direct("z")
>directUnionSingle : Record<"z", string>
>direct("z") : Record<"z", string>
>direct : <A extends string>(a: A | A[]) => Record<A, string>
>"z" : "z"

const directUnionArray = direct(["z", "y"])
>directUnionArray : Record<"z" | "y", string>
>direct(["z", "y"]) : Record<"z" | "y", string>
>direct : <A extends string>(a: A | A[]) => Record<A, string>
>["z", "y"] : ("z" | "y")[]
>"z" : "z"
>"y" : "y"

const nestedSingle = nested({fields: "z"})
>nestedSingle : Record<"z", string>
>nested({fields: "z"}) : Record<"z", string>
>nested : <A extends string>(a: { fields: A; }) => Record<A, string>
>{fields: "z"} : { fields: "z"; }
>fields : "z"
>"z" : "z"

const nestedUnionSingle = nestedUnion({fields: "z"})
>nestedUnionSingle : Record<"z", string>
>nestedUnion({fields: "z"}) : Record<"z", string>
>nestedUnion : <A extends string>(a: { fields: A | A[]; }) => Record<A, string>
>{fields: "z"} : { fields: "z"; }
>fields : "z"
>"z" : "z"

const nestedUnionArray = nestedUnion({fields: ["z", "y"]})
>nestedUnionArray : Record<"z" | "y", string>
>nestedUnion({fields: ["z", "y"]}) : Record<"z" | "y", string>
>nestedUnion : <A extends string>(a: { fields: A | A[]; }) => Record<A, string>
>{fields: ["z", "y"]} : { fields: ("z" | "y")[]; }
>fields : ("z" | "y")[]
>["z", "y"] : ("z" | "y")[]
>"z" : "z"
>"y" : "y"

declare function hasZField(arg: { z: string }): void
>hasZField : (arg: {    z: string;}) => void
>arg : { z: string; }
>z : string

hasZField(directUnionSingle) // ok
>hasZField(directUnionSingle) : void
>hasZField : (arg: { z: string; }) => void
>directUnionSingle : Record<"z", string>

hasZField(directUnionArray) // ok
>hasZField(directUnionArray) : void
>hasZField : (arg: { z: string; }) => void
>directUnionArray : Record<"z" | "y", string>

hasZField(nestedSingle) // ok
>hasZField(nestedSingle) : void
>hasZField : (arg: { z: string; }) => void
>nestedSingle : Record<"z", string>

hasZField(nestedUnionSingle) // ok
>hasZField(nestedUnionSingle) : void
>hasZField : (arg: { z: string; }) => void
>nestedUnionSingle : Record<"z", string>

hasZField(nestedUnionArray) // ok
>hasZField(nestedUnionArray) : void
>hasZField : (arg: { z: string; }) => void
>nestedUnionArray : Record<"z" | "y", string>