Skip to content

Commit 887b306

Browse files
committed
Add tests
1 parent 6dc8b5f commit 887b306

File tree

1 file changed

+142
-0
lines changed

1 file changed

+142
-0
lines changed
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
// @strict: true
2+
// @target: es6
3+
4+
// #6611
5+
6+
export interface A<a> {
7+
value: a;
8+
}
9+
10+
function fn<a>(values: A<a>, value: a) : void {
11+
}
12+
13+
declare let handlers: A<(value: number) => void>;
14+
fn(handlers, value => alert(value));
15+
16+
// #21382
17+
18+
interface BaseProps<T> {
19+
initialValues: T;
20+
nextValues: (cur: T) => T;
21+
}
22+
declare class Component<P> { constructor(props: P); props: P; }
23+
declare class GenericComponent<Props = {}, Values = object>
24+
extends Component<Props & BaseProps<Values>> {
25+
iv: Values;
26+
}
27+
28+
new GenericComponent({ initialValues: 12, nextValues: val => 12 });
29+
30+
// #22149
31+
32+
declare function useStringOrNumber<T extends string | number>(t: T, useIt: T extends string ? ((s: string) => void) : ((n: number) => void)): void;
33+
useStringOrNumber("", foo => {});
34+
35+
// #25299
36+
37+
type ActionType<P> = string & { attachPayloadTypeHack?: P & never }
38+
39+
type Handler<S, P> = P extends void
40+
? (state: S) => S
41+
: (state: S, payload: P) => S
42+
43+
interface ActionHandler<S, P> {
44+
actionType: ActionType<P>
45+
handler: Handler<S, P>
46+
}
47+
48+
declare function handler<S, P>(actionType: ActionType<P>, handler: Handler<S, P>): ActionHandler<S, P>
49+
50+
declare function createReducer<S>(
51+
defaultState: S,
52+
...actionHandlers: ActionHandler<S, any>[]
53+
): any
54+
55+
interface AppState {
56+
dummy: string
57+
}
58+
59+
const defaultState: AppState = {
60+
dummy: ''
61+
}
62+
63+
const NON_VOID_ACTION: ActionType<number> = 'NON_VOID_ACTION'
64+
, VOID_ACTION: ActionType<void> = 'VOID_ACTION'
65+
66+
createReducer(
67+
defaultState,
68+
handler(NON_VOID_ACTION, (state, _payload) => state),
69+
handler(VOID_ACTION, state => state)
70+
)
71+
72+
// #25814
73+
74+
type R = {
75+
a: (x: number) => void;
76+
b: (x: string) => void;
77+
};
78+
79+
type O = {
80+
on<P extends keyof R>(x: P, callback: R[P]): void;
81+
};
82+
83+
declare var x: O;
84+
x.on('a', a => {});
85+
86+
// #29775
87+
88+
namespace N1 {
89+
90+
declare class Component<P> {
91+
constructor(props: P);
92+
}
93+
94+
interface ComponentClass<P = {}> {
95+
new (props: P): Component<P>;
96+
}
97+
98+
type CreateElementChildren<P> =
99+
P extends { children?: infer C }
100+
? C extends any[]
101+
? C
102+
: C[]
103+
: unknown;
104+
105+
declare function createElement<P extends {}>(
106+
type: ComponentClass<P>,
107+
...children: CreateElementChildren<P>
108+
): any;
109+
110+
declare function createElement2<P extends {}>(
111+
type: ComponentClass<P>,
112+
child: CreateElementChildren<P>
113+
): any;
114+
115+
class InferFunctionTypes extends Component<{children: (foo: number) => string}> {}
116+
117+
createElement(InferFunctionTypes, (foo) => "" + foo);
118+
119+
createElement2(InferFunctionTypes, [(foo) => "" + foo]);
120+
121+
}
122+
123+
// #30341
124+
125+
type InnerBox<T> = {
126+
value: T;
127+
}
128+
129+
type OuterBox<T> = {
130+
inner: InnerBox<T>
131+
};
132+
133+
type BoxConsumerFromOuterBox<T> =
134+
T extends OuterBox<infer U> ?
135+
(box: InnerBox<U>) => void :
136+
never;
137+
138+
declare function passContentsToFunc<T>(outerBox: T, consumer: BoxConsumerFromOuterBox<T>): void;
139+
140+
declare const outerBoxOfString: OuterBox<string>;
141+
142+
passContentsToFunc(outerBoxOfString, box => box.value);

0 commit comments

Comments
 (0)