File: keyofIntersection.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 (59 lines) | stat: -rw-r--r-- 1,474 bytes parent folder | download | duplicates (3)
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
=== tests/cases/conformance/types/keyof/keyofIntersection.ts ===
type A = { a: string };
>A : { a: string; }
>a : string

type B = { b: string };
>B : { b: string; }
>b : string

type T01 = keyof (A & B);  // "a" | "b"
>T01 : "b" | "a"

type T02<T> = keyof (T & B);  // "b" | keyof T
>T02 : keyof T | "b"

type T03<U> = keyof (A & U);  // "a" | keyof U
>T03 : "a" | keyof U

type T04<T, U> = keyof (T & U);  // keyof T | keyof U
>T04 : keyof T | keyof U

type T05 = T02<A>;  // "a" | "b"
>T05 : "b" | "a"

type T06 = T03<B>;  // "a" | "b"
>T06 : "b" | "a"

type T07 = T04<A, B>;  // "a" | "b"
>T07 : "b" | "a"

// Repros from #22291

type Example1<T extends string, U extends string> = keyof (Record<T, any> & Record<U, any>);
>Example1 : T | U

type Result1 = Example1<'x', 'y'>;  // "x" | "y"
>Result1 : "x" | "y"

type Result2 = keyof (Record<'x', any> & Record<'y', any>);  // "x" | "y"
>Result2 : "x" | "y"

type Example3<T extends string> = keyof (Record<T, any>);
>Example3 : T

type Result3 = Example3<'x' | 'y'>;  // "x" | "y"
>Result3 : "x" | "y"

type Example4<T extends string, U extends string> = (Record<T, any> & Record<U, any>);
>Example4 : Example4<T, U>

type Result4 = keyof Example4<'x', 'y'>;  // "x" | "y"
>Result4 : "x" | "y"

type Example5<T, U> = keyof (T & U);
>Example5 : keyof T | keyof U

type Result5 = Example5<Record<'x', any>, Record<'y', any>>;  // "x" | "y"
>Result5 : "x" | "y"