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 187 188 189 190
|
=== tests/cases/compiler/index.tsx ===
interface ActionsObject<State> {
[prop: string]: (state: State) => State;
>prop : string
>state : State
}
interface Options<State, Actions> {
state?: State;
>state : State | undefined
view?: (state: State, actions: Actions) => any;
>view : ((state: State, actions: Actions) => any) | undefined
>state : State
>actions : Actions
actions: string | Actions;
>actions : string | Actions
}
declare function app<State, Actions extends ActionsObject<State>>(obj: Options<State, Actions>): void;
>app : <State, Actions extends ActionsObject<State>>(obj: Options<State, Actions>) => void
>obj : Options<State, Actions>
app({
>app({ state: 100, actions: { foo: s => s // Should be typed number => number }, view: (s, a) => undefined as any,}) : void
>app : <State, Actions extends ActionsObject<State>>(obj: Options<State, Actions>) => void
>{ state: 100, actions: { foo: s => s // Should be typed number => number }, view: (s, a) => undefined as any,} : { state: number; actions: { foo: (s: number) => number; }; view: (s: number, a: { foo: (s: number) => number; }) => any; }
state: 100,
>state : number
>100 : 100
actions: {
>actions : { foo: (s: number) => number; }
>{ foo: s => s // Should be typed number => number } : { foo: (s: number) => number; }
foo: s => s // Should be typed number => number
>foo : (s: number) => number
>s => s : (s: number) => number
>s : number
>s : number
},
view: (s, a) => undefined as any,
>view : (s: number, a: { foo: (s: number) => number; }) => any
>(s, a) => undefined as any : (s: number, a: { foo: (s: number) => number; }) => any
>s : number
>a : { foo: (s: number) => number; }
>undefined as any : any
>undefined : undefined
});
interface Bar {
bar: (a: number) => void;
>bar : (a: number) => void
>a : number
}
declare function foo<T extends Bar>(x: string | T): T;
>foo : <T extends Bar>(x: string | T) => T
>x : string | T
const y = foo({
>y : { bar(x: number): void; }
>foo({ bar(x) { // Should be typed number => void }}) : { bar(x: number): void; }
>foo : <T extends Bar>(x: string | T) => T
>{ bar(x) { // Should be typed number => void }} : { bar(x: number): void; }
bar(x) { // Should be typed number => void
>bar : (x: number) => void
>x : number
}
});
interface Options2<State, Actions> {
state?: State;
>state : State | undefined
view?: (state: State, actions: Actions) => any;
>view : ((state: State, actions: Actions) => any) | undefined
>state : State
>actions : Actions
actions?: Actions;
>actions : Actions | undefined
}
declare function app2<State, Actions extends ActionsObject<State>>(obj: Options2<State, Actions>): void;
>app2 : <State, Actions extends ActionsObject<State>>(obj: Options2<State, Actions>) => void
>obj : Options2<State, Actions>
app2({
>app2({ state: 100, actions: { foo: s => s // Should be typed number => number }, view: (s, a) => undefined as any,}) : void
>app2 : <State, Actions extends ActionsObject<State>>(obj: Options2<State, Actions>) => void
>{ state: 100, actions: { foo: s => s // Should be typed number => number }, view: (s, a) => undefined as any,} : { state: number; actions: { foo: (s: number) => number; }; view: (s: number, a: { foo: (s: number) => number; }) => any; }
state: 100,
>state : number
>100 : 100
actions: {
>actions : { foo: (s: number) => number; }
>{ foo: s => s // Should be typed number => number } : { foo: (s: number) => number; }
foo: s => s // Should be typed number => number
>foo : (s: number) => number
>s => s : (s: number) => number
>s : number
>s : number
},
view: (s, a) => undefined as any,
>view : (s: number, a: { foo: (s: number) => number; }) => any
>(s, a) => undefined as any : (s: number, a: { foo: (s: number) => number; }) => any
>s : number
>a : { foo: (s: number) => number; }
>undefined as any : any
>undefined : undefined
});
type ActionsArray<State> = ((state: State) => State)[];
>ActionsArray : ActionsArray<State>
>state : State
declare function app3<State, Actions extends ActionsArray<State>>(obj: Options<State, Actions>): void;
>app3 : <State, Actions extends ActionsArray<State>>(obj: Options<State, Actions>) => void
>obj : Options<State, Actions>
app3({
>app3({ state: 100, actions: [ s => s // Should be typed number => number ], view: (s, a) => undefined as any,}) : void
>app3 : <State, Actions extends ActionsArray<State>>(obj: Options<State, Actions>) => void
>{ state: 100, actions: [ s => s // Should be typed number => number ], view: (s, a) => undefined as any,} : { state: number; actions: ((s: number) => number)[]; view: (s: number, a: ((s: number) => number)[]) => any; }
state: 100,
>state : number
>100 : 100
actions: [
>actions : ((s: number) => number)[]
>[ s => s // Should be typed number => number ] : ((s: number) => number)[]
s => s // Should be typed number => number
>s => s : (s: number) => number
>s : number
>s : number
],
view: (s, a) => undefined as any,
>view : (s: number, a: ((s: number) => number)[]) => any
>(s, a) => undefined as any : (s: number, a: ((s: number) => number)[]) => any
>s : number
>a : ((s: number) => number)[]
>undefined as any : any
>undefined : undefined
});
namespace JSX {
export interface Element {}
export interface IntrinsicElements {}
}
interface ActionsObjectOr<State> {
[prop: string]: ((state: State) => State) | State;
>prop : string
>state : State
}
declare function App4<State, Actions extends ActionsObjectOr<State>>(props: Options<State, Actions>["actions"] & { state: State }): JSX.Element;
>App4 : <State, Actions extends ActionsObjectOr<State>>(props: Options<State, Actions>["actions"] & { state: State;}) => JSX.Element
>props : (string | Actions) & { state: State; }
>state : State
>JSX : any
const a = <App4 state={100} foo={s => s} />; // TODO: should be number => number, but JSX resolution is missing an inferential pass
>a : JSX.Element
><App4 state={100} foo={s => s} /> : JSX.Element
>App4 : <State, Actions extends ActionsObjectOr<State>>(props: (string | Actions) & { state: State; }) => JSX.Element
>state : number
>100 : 100
>foo : (s: number) => number
>s => s : (s: number) => number
>s : number
>s : number
|