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 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
// @strict: true
// @target: es6
// #6611
export interface A<a> {
value: a;
}
function fn<a>(values: A<a>, value: a) : void {
}
declare let handlers: A<(value: number) => void>;
fn(handlers, value => alert(value));
// #21382
interface BaseProps<T> {
initialValues: T;
nextValues: (cur: T) => T;
}
declare class Component<P> { constructor(props: P); props: P; }
declare class GenericComponent<Props = {}, Values = object>
extends Component<Props & BaseProps<Values>> {
iv: Values;
}
new GenericComponent({ initialValues: 12, nextValues: val => 12 });
// #22149
declare function useStringOrNumber<T extends string | number>(t: T, useIt: T extends string ? ((s: string) => void) : ((n: number) => void)): void;
useStringOrNumber("", foo => {});
// #25299
type ActionType<P> = string & { attachPayloadTypeHack?: P & never }
type Handler<S, P> = P extends void
? (state: S) => S
: (state: S, payload: P) => S
interface ActionHandler<S, P> {
actionType: ActionType<P>
handler: Handler<S, P>
}
declare function handler<S, P>(actionType: ActionType<P>, handler: Handler<S, P>): ActionHandler<S, P>
declare function createReducer<S>(
defaultState: S,
...actionHandlers: ActionHandler<S, any>[]
): any
interface AppState {
dummy: string
}
const defaultState: AppState = {
dummy: ''
}
const NON_VOID_ACTION: ActionType<number> = 'NON_VOID_ACTION'
, VOID_ACTION: ActionType<void> = 'VOID_ACTION'
createReducer(
defaultState,
handler(NON_VOID_ACTION, (state, _payload) => state),
handler(VOID_ACTION, state => state)
)
// #25814
type R = {
a: (x: number) => void;
b: (x: string) => void;
};
type O = {
on<P extends keyof R>(x: P, callback: R[P]): void;
};
declare var x: O;
x.on('a', a => {});
// #29775
namespace N1 {
declare class Component<P> {
constructor(props: P);
}
interface ComponentClass<P = {}> {
new (props: P): Component<P>;
}
type CreateElementChildren<P> =
P extends { children?: infer C }
? C extends any[]
? C
: C[]
: unknown;
declare function createElement<P extends {}>(
type: ComponentClass<P>,
...children: CreateElementChildren<P>
): any;
declare function createElement2<P extends {}>(
type: ComponentClass<P>,
child: CreateElementChildren<P>
): any;
class InferFunctionTypes extends Component<{children: (foo: number) => string}> {}
createElement(InferFunctionTypes, (foo) => "" + foo);
createElement2(InferFunctionTypes, [(foo) => "" + foo]);
}
// #30341
type InnerBox<T> = {
value: T;
}
type OuterBox<T> = {
inner: InnerBox<T>
};
type BoxConsumerFromOuterBox<T> =
T extends OuterBox<infer U> ?
(box: InnerBox<U>) => void :
never;
declare function passContentsToFunc<T>(outerBox: T, consumer: BoxConsumerFromOuterBox<T>): void;
declare const outerBoxOfString: OuterBox<string>;
passContentsToFunc(outerBoxOfString, box => box.value);
// Repro from #32349
type DooDad = 'SOMETHING' | 'ELSE' ;
class Interesting {
public compiles = () : Promise<DooDad> => {
return Promise.resolve().then(() => {
if (1 < 2) {
return 'SOMETHING';
}
return 'ELSE';
});
};
public doesnt = () : Promise<DooDad> => {
return Promise.resolve().then(() => {
return 'ELSE';
});
};
public slightlyDifferentErrorMessage = () : Promise<DooDad> => {
return Promise.resolve().then(() => {
if (1 < 2) {
return 'SOMETHING';
}
return 'SOMETHING';
});
};
}
// Repro from #32349
declare function invoke<T>(f: () => T): T;
let xx: 0 | 1 | 2 = invoke(() => 1);
// Repro from #32416
declare function assignPartial<T>(target: T, partial: Partial<T>): T;
let obj = {
foo(bar: string) {}
}
assignPartial(obj, { foo(...args) {} }); // args has type [string]
|