File: intersectionTypeInference2.types

package info (click to toggle)
node-typescript 3.3.3333-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 324,548 kB
  • sloc: makefile: 6; sh: 3
file content (49 lines) | stat: -rw-r--r-- 1,398 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
41
42
43
44
45
46
47
48
49
=== tests/cases/conformance/types/intersection/intersectionTypeInference2.ts ===
declare function f<T>(x: { prop: T }): T;
>f : <T>(x: { prop: T; }) => T
>x : { prop: T; }
>prop : T

declare const a: { prop: string } & { prop: number };
>a : { prop: string; } & { prop: number; }
>prop : string
>prop : number

declare const b: { prop: string & number };
>b : { prop: string & number; }
>prop : string & number

f(a);  // string & number
>f(a) : string & number
>f : <T>(x: { prop: T; }) => T
>a : { prop: string; } & { prop: number; }

f(b);  // string & number
>f(b) : string & number
>f : <T>(x: { prop: T; }) => T
>b : { prop: string & number; }

// Repro from #18354

declare function f2<T, Key extends keyof T>(obj: {[K in keyof T]: T[K]}, key: Key): T[Key];
>f2 : <T, Key extends keyof T>(obj: { [K in keyof T]: T[K]; }, key: Key) => T[Key]
>obj : { [K in keyof T]: T[K]; }
>key : Key

declare const obj: { a: string } & { b: string };
>obj : { a: string; } & { b: string; }
>a : string
>b : string

f2(obj, 'a');
>f2(obj, 'a') : string
>f2 : <T, Key extends keyof T>(obj: { [K in keyof T]: T[K]; }, key: Key) => T[Key]
>obj : { a: string; } & { b: string; }
>'a' : "a"

f2(obj, 'b');
>f2(obj, 'b') : string
>f2 : <T, Key extends keyof T>(obj: { [K in keyof T]: T[K]; }, key: Key) => T[Key]
>obj : { a: string; } & { b: string; }
>'b' : "b"