Skip to content

Commit de76d55

Browse files
committed
Accept new baselines
1 parent 887b306 commit de76d55

File tree

3 files changed

+901
-0
lines changed

3 files changed

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

0 commit comments

Comments
 (0)