File: unionAndIntersectionInference3.js

package info (click to toggle)
node-typescript 4.9.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 533,908 kB
  • sloc: javascript: 2,018,330; makefile: 7; sh: 1
file content (108 lines) | stat: -rw-r--r-- 2,542 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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//// [unionAndIntersectionInference3.ts]
// Repro from #30720

type Maybe<T> = T | undefined;
declare function concatMaybe<T>(...args: (Maybe<T> | Maybe<T>[])[]): T[];
concatMaybe([1, 2, 3], 4);

// Repros from #32247

const g: <U, R, S>(com: () => Iterator<S, U, R> | AsyncIterator<S, U, R>) => Promise<U> = async <U, R, S>(com: () => Iterator<S, U, R> | AsyncIterator<S, U, R>): Promise<U> => {
  throw com;
};

interface Foo1<T> {
    test(value: T): void;
}

interface Bar1<T> {
    test(value: T | PromiseLike<T>): void;
}

declare let f1: <T>(x: Foo1<T> | Bar1<T>) => Promise<T>;
declare let f2: <U>(x: Foo1<U> | Bar1<U>) => Promise<U>;

f1 = f2;
f2 = f1;

type Foo2<T> = {
    test(value: T): void;
}

type Bar2<T> = {
    test(value: T | PromiseLike<T>): void;
}

declare let g1: <T>(x: Foo2<T> | Bar2<T>) => Promise<T>;
declare let g2: <U>(x: Foo2<U> | Bar2<U>) => Promise<U>;

g1 = g2;
g2 = g1;

// Repro from #32572

declare function foo1<T>(obj: string[] & Iterable<T>): T;
declare function foo2<T>(obj: string[] & T): T;

declare let sa: string[];
declare let sx: string[] & { extra: number };

let x1 = foo1(sa);  // string
let y1 = foo1(sx);  // string

let x2 = foo2(sa);  // unknown
let y2 = foo2(sx);  // { extra: number }

// Repro from #33490

declare class Component<P> { props: P }

export type ComponentClass<P> = new (props: P) => Component<P>;
export type FunctionComponent<P> = (props: P) => null;

export type ComponentType<P> = FunctionComponent<P> | ComponentClass<P>;

export interface RouteComponentProps { route: string }

declare function withRouter<
  P extends RouteComponentProps,
  C extends ComponentType<P>
>(
  component: C & ComponentType<P>
): ComponentClass<Omit<P, keyof RouteComponentProps>>;

interface Props extends RouteComponentProps { username: string }

declare const MyComponent: ComponentType<Props>;

withRouter(MyComponent);

// Repro from #33490

type AB<T> = { a: T } | { b: T };

// T & AB<U> normalizes to T & { a: U } | T & { b: U } below
declare function foo<T, U>(obj: T & AB<U>): [T, U];
declare let ab: AB<string>;

let z = foo(ab);  // [AB<string>, string]


//// [unionAndIntersectionInference3.js]
// Repro from #30720
concatMaybe([1, 2, 3], 4);
// Repros from #32247
const g = async (com) => {
    throw com;
};
f1 = f2;
f2 = f1;
g1 = g2;
g2 = g1;
let x1 = foo1(sa); // string
let y1 = foo1(sx); // string
let x2 = foo2(sa); // unknown
let y2 = foo2(sx); // { extra: number }
withRouter(MyComponent);
let z = foo(ab); // [AB<string>, string]
export {};