diff --git a/tests/baselines/reference/instantiateContextualTypes.js b/tests/baselines/reference/instantiateContextualTypes.js new file mode 100644 index 00000000000..3a33b54278c --- /dev/null +++ b/tests/baselines/reference/instantiateContextualTypes.js @@ -0,0 +1,164 @@ +//// [instantiateContextualTypes.ts] +// #6611 + +export interface A { + value: a; +} + +function fn(values: A, value: a) : void { +} + +declare let handlers: A<(value: number) => void>; +fn(handlers, value => alert(value)); + +// #21382 + +interface BaseProps { + initialValues: T; + nextValues: (cur: T) => T; +} +declare class Component

{ constructor(props: P); props: P; } +declare class GenericComponent + extends Component> { + iv: Values; +} + +new GenericComponent({ initialValues: 12, nextValues: val => 12 }); + +// #22149 + +declare function useStringOrNumber(t: T, useIt: T extends string ? ((s: string) => void) : ((n: number) => void)): void; +useStringOrNumber("", foo => {}); + +// #25299 + +type ActionType

= string & { attachPayloadTypeHack?: P & never } + +type Handler = P extends void + ? (state: S) => S + : (state: S, payload: P) => S + +interface ActionHandler { + actionType: ActionType

+ handler: Handler +} + +declare function handler(actionType: ActionType

, handler: Handler): ActionHandler + +declare function createReducer( + defaultState: S, + ...actionHandlers: ActionHandler[] + ): any + +interface AppState { + dummy: string +} + +const defaultState: AppState = { + dummy: '' +} + +const NON_VOID_ACTION: ActionType = 'NON_VOID_ACTION' + , VOID_ACTION: ActionType = '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

(x: P, callback: R[P]): void; +}; + +declare var x: O; +x.on('a', a => {}); + +// #29775 + +namespace N1 { + +declare class Component

{ + constructor(props: P); +} + +interface ComponentClass

{ + new (props: P): Component

; +} + +type CreateElementChildren

= + P extends { children?: infer C } + ? C extends any[] + ? C + : C[] + : unknown; + +declare function createElement

( + type: ComponentClass

, + ...children: CreateElementChildren

+): any; + +declare function createElement2

( + type: ComponentClass

, + child: CreateElementChildren

+): any; + +class InferFunctionTypes extends Component<{children: (foo: number) => string}> {} + +createElement(InferFunctionTypes, (foo) => "" + foo); + +createElement2(InferFunctionTypes, [(foo) => "" + foo]); + +} + +// #30341 + +type InnerBox = { + value: T; +} + +type OuterBox = { + inner: InnerBox +}; + +type BoxConsumerFromOuterBox = + T extends OuterBox ? + (box: InnerBox) => void : + never; + +declare function passContentsToFunc(outerBox: T, consumer: BoxConsumerFromOuterBox): void; + +declare const outerBoxOfString: OuterBox; + +passContentsToFunc(outerBoxOfString, box => box.value); + + +//// [instantiateContextualTypes.js] +// #6611 +function fn(values, value) { +} +fn(handlers, value => alert(value)); +new GenericComponent({ initialValues: 12, nextValues: val => 12 }); +useStringOrNumber("", foo => { }); +const defaultState = { + dummy: '' +}; +const NON_VOID_ACTION = 'NON_VOID_ACTION', VOID_ACTION = 'VOID_ACTION'; +createReducer(defaultState, handler(NON_VOID_ACTION, (state, _payload) => state), handler(VOID_ACTION, state => state)); +x.on('a', a => { }); +// #29775 +var N1; +(function (N1) { + class InferFunctionTypes extends Component { + } + createElement(InferFunctionTypes, (foo) => "" + foo); + createElement2(InferFunctionTypes, [(foo) => "" + foo]); +})(N1 || (N1 = {})); +passContentsToFunc(outerBoxOfString, box => box.value); diff --git a/tests/baselines/reference/instantiateContextualTypes.symbols b/tests/baselines/reference/instantiateContextualTypes.symbols new file mode 100644 index 00000000000..098be95bac5 --- /dev/null +++ b/tests/baselines/reference/instantiateContextualTypes.symbols @@ -0,0 +1,409 @@ +=== tests/cases/compiler/instantiateContextualTypes.ts === +// #6611 + +export interface A { +>A : Symbol(A, Decl(instantiateContextualTypes.ts, 0, 0)) +>a : Symbol(a, Decl(instantiateContextualTypes.ts, 2, 19)) + + value: a; +>value : Symbol(A.value, Decl(instantiateContextualTypes.ts, 2, 23)) +>a : Symbol(a, Decl(instantiateContextualTypes.ts, 2, 19)) +} + +function fn(values: A, value: a) : void { +>fn : Symbol(fn, Decl(instantiateContextualTypes.ts, 4, 1)) +>a : Symbol(a, Decl(instantiateContextualTypes.ts, 6, 12)) +>values : Symbol(values, Decl(instantiateContextualTypes.ts, 6, 15)) +>A : Symbol(A, Decl(instantiateContextualTypes.ts, 0, 0)) +>a : Symbol(a, Decl(instantiateContextualTypes.ts, 6, 12)) +>value : Symbol(value, Decl(instantiateContextualTypes.ts, 6, 28)) +>a : Symbol(a, Decl(instantiateContextualTypes.ts, 6, 12)) +} + +declare let handlers: A<(value: number) => void>; +>handlers : Symbol(handlers, Decl(instantiateContextualTypes.ts, 9, 11)) +>A : Symbol(A, Decl(instantiateContextualTypes.ts, 0, 0)) +>value : Symbol(value, Decl(instantiateContextualTypes.ts, 9, 25)) + +fn(handlers, value => alert(value)); +>fn : Symbol(fn, Decl(instantiateContextualTypes.ts, 4, 1)) +>handlers : Symbol(handlers, Decl(instantiateContextualTypes.ts, 9, 11)) +>value : Symbol(value, Decl(instantiateContextualTypes.ts, 10, 12)) +>alert : Symbol(alert, Decl(lib.dom.d.ts, --, --)) +>value : Symbol(value, Decl(instantiateContextualTypes.ts, 10, 12)) + +// #21382 + +interface BaseProps { +>BaseProps : Symbol(BaseProps, Decl(instantiateContextualTypes.ts, 10, 36)) +>T : Symbol(T, Decl(instantiateContextualTypes.ts, 14, 20)) + + initialValues: T; +>initialValues : Symbol(BaseProps.initialValues, Decl(instantiateContextualTypes.ts, 14, 24)) +>T : Symbol(T, Decl(instantiateContextualTypes.ts, 14, 20)) + + nextValues: (cur: T) => T; +>nextValues : Symbol(BaseProps.nextValues, Decl(instantiateContextualTypes.ts, 15, 19)) +>cur : Symbol(cur, Decl(instantiateContextualTypes.ts, 16, 15)) +>T : Symbol(T, Decl(instantiateContextualTypes.ts, 14, 20)) +>T : Symbol(T, Decl(instantiateContextualTypes.ts, 14, 20)) +} +declare class Component

{ constructor(props: P); props: P; } +>Component : Symbol(Component, Decl(instantiateContextualTypes.ts, 17, 1)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 18, 24)) +>props : Symbol(props, Decl(instantiateContextualTypes.ts, 18, 41)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 18, 24)) +>props : Symbol(Component.props, Decl(instantiateContextualTypes.ts, 18, 51)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 18, 24)) + +declare class GenericComponent +>GenericComponent : Symbol(GenericComponent, Decl(instantiateContextualTypes.ts, 18, 63)) +>Props : Symbol(Props, Decl(instantiateContextualTypes.ts, 19, 31)) +>Values : Symbol(Values, Decl(instantiateContextualTypes.ts, 19, 42)) + + extends Component> { +>Component : Symbol(Component, Decl(instantiateContextualTypes.ts, 17, 1)) +>Props : Symbol(Props, Decl(instantiateContextualTypes.ts, 19, 31)) +>BaseProps : Symbol(BaseProps, Decl(instantiateContextualTypes.ts, 10, 36)) +>Values : Symbol(Values, Decl(instantiateContextualTypes.ts, 19, 42)) + + iv: Values; +>iv : Symbol(GenericComponent.iv, Decl(instantiateContextualTypes.ts, 20, 50)) +>Values : Symbol(Values, Decl(instantiateContextualTypes.ts, 19, 42)) +} + +new GenericComponent({ initialValues: 12, nextValues: val => 12 }); +>GenericComponent : Symbol(GenericComponent, Decl(instantiateContextualTypes.ts, 18, 63)) +>initialValues : Symbol(initialValues, Decl(instantiateContextualTypes.ts, 24, 22)) +>nextValues : Symbol(nextValues, Decl(instantiateContextualTypes.ts, 24, 41)) +>val : Symbol(val, Decl(instantiateContextualTypes.ts, 24, 53)) + +// #22149 + +declare function useStringOrNumber(t: T, useIt: T extends string ? ((s: string) => void) : ((n: number) => void)): void; +>useStringOrNumber : Symbol(useStringOrNumber, Decl(instantiateContextualTypes.ts, 24, 67)) +>T : Symbol(T, Decl(instantiateContextualTypes.ts, 28, 35)) +>t : Symbol(t, Decl(instantiateContextualTypes.ts, 28, 62)) +>T : Symbol(T, Decl(instantiateContextualTypes.ts, 28, 35)) +>useIt : Symbol(useIt, Decl(instantiateContextualTypes.ts, 28, 67)) +>T : Symbol(T, Decl(instantiateContextualTypes.ts, 28, 35)) +>s : Symbol(s, Decl(instantiateContextualTypes.ts, 28, 96)) +>n : Symbol(n, Decl(instantiateContextualTypes.ts, 28, 120)) + +useStringOrNumber("", foo => {}); +>useStringOrNumber : Symbol(useStringOrNumber, Decl(instantiateContextualTypes.ts, 24, 67)) +>foo : Symbol(foo, Decl(instantiateContextualTypes.ts, 29, 21)) + +// #25299 + +type ActionType

= string & { attachPayloadTypeHack?: P & never } +>ActionType : Symbol(ActionType, Decl(instantiateContextualTypes.ts, 29, 33)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 33, 16)) +>attachPayloadTypeHack : Symbol(attachPayloadTypeHack, Decl(instantiateContextualTypes.ts, 33, 31)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 33, 16)) + +type Handler = P extends void +>Handler : Symbol(Handler, Decl(instantiateContextualTypes.ts, 33, 67)) +>S : Symbol(S, Decl(instantiateContextualTypes.ts, 35, 13)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 35, 15)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 35, 15)) + + ? (state: S) => S +>state : Symbol(state, Decl(instantiateContextualTypes.ts, 36, 7)) +>S : Symbol(S, Decl(instantiateContextualTypes.ts, 35, 13)) +>S : Symbol(S, Decl(instantiateContextualTypes.ts, 35, 13)) + + : (state: S, payload: P) => S +>state : Symbol(state, Decl(instantiateContextualTypes.ts, 37, 7)) +>S : Symbol(S, Decl(instantiateContextualTypes.ts, 35, 13)) +>payload : Symbol(payload, Decl(instantiateContextualTypes.ts, 37, 16)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 35, 15)) +>S : Symbol(S, Decl(instantiateContextualTypes.ts, 35, 13)) + +interface ActionHandler { +>ActionHandler : Symbol(ActionHandler, Decl(instantiateContextualTypes.ts, 37, 33)) +>S : Symbol(S, Decl(instantiateContextualTypes.ts, 39, 24)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 39, 26)) + + actionType: ActionType

+>actionType : Symbol(ActionHandler.actionType, Decl(instantiateContextualTypes.ts, 39, 31)) +>ActionType : Symbol(ActionType, Decl(instantiateContextualTypes.ts, 29, 33)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 39, 26)) + + handler: Handler +>handler : Symbol(ActionHandler.handler, Decl(instantiateContextualTypes.ts, 40, 29)) +>Handler : Symbol(Handler, Decl(instantiateContextualTypes.ts, 33, 67)) +>S : Symbol(S, Decl(instantiateContextualTypes.ts, 39, 24)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 39, 26)) +} + +declare function handler(actionType: ActionType

, handler: Handler): ActionHandler +>handler : Symbol(handler, Decl(instantiateContextualTypes.ts, 42, 1)) +>S : Symbol(S, Decl(instantiateContextualTypes.ts, 44, 25)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 44, 27)) +>actionType : Symbol(actionType, Decl(instantiateContextualTypes.ts, 44, 31)) +>ActionType : Symbol(ActionType, Decl(instantiateContextualTypes.ts, 29, 33)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 44, 27)) +>handler : Symbol(handler, Decl(instantiateContextualTypes.ts, 44, 57)) +>Handler : Symbol(Handler, Decl(instantiateContextualTypes.ts, 33, 67)) +>S : Symbol(S, Decl(instantiateContextualTypes.ts, 44, 25)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 44, 27)) +>ActionHandler : Symbol(ActionHandler, Decl(instantiateContextualTypes.ts, 37, 33)) +>S : Symbol(S, Decl(instantiateContextualTypes.ts, 44, 25)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 44, 27)) + +declare function createReducer( +>createReducer : Symbol(createReducer, Decl(instantiateContextualTypes.ts, 44, 102)) +>S : Symbol(S, Decl(instantiateContextualTypes.ts, 46, 31)) + + defaultState: S, +>defaultState : Symbol(defaultState, Decl(instantiateContextualTypes.ts, 46, 34)) +>S : Symbol(S, Decl(instantiateContextualTypes.ts, 46, 31)) + + ...actionHandlers: ActionHandler[] +>actionHandlers : Symbol(actionHandlers, Decl(instantiateContextualTypes.ts, 47, 24)) +>ActionHandler : Symbol(ActionHandler, Decl(instantiateContextualTypes.ts, 37, 33)) +>S : Symbol(S, Decl(instantiateContextualTypes.ts, 46, 31)) + + ): any + +interface AppState { +>AppState : Symbol(AppState, Decl(instantiateContextualTypes.ts, 49, 10)) + + dummy: string +>dummy : Symbol(AppState.dummy, Decl(instantiateContextualTypes.ts, 51, 20)) +} + +const defaultState: AppState = { +>defaultState : Symbol(defaultState, Decl(instantiateContextualTypes.ts, 55, 5)) +>AppState : Symbol(AppState, Decl(instantiateContextualTypes.ts, 49, 10)) + + dummy: '' +>dummy : Symbol(dummy, Decl(instantiateContextualTypes.ts, 55, 32)) +} + +const NON_VOID_ACTION: ActionType = 'NON_VOID_ACTION' +>NON_VOID_ACTION : Symbol(NON_VOID_ACTION, Decl(instantiateContextualTypes.ts, 59, 5)) +>ActionType : Symbol(ActionType, Decl(instantiateContextualTypes.ts, 29, 33)) + + , VOID_ACTION: ActionType = 'VOID_ACTION' +>VOID_ACTION : Symbol(VOID_ACTION, Decl(instantiateContextualTypes.ts, 60, 5)) +>ActionType : Symbol(ActionType, Decl(instantiateContextualTypes.ts, 29, 33)) + +createReducer( +>createReducer : Symbol(createReducer, Decl(instantiateContextualTypes.ts, 44, 102)) + + defaultState, +>defaultState : Symbol(defaultState, Decl(instantiateContextualTypes.ts, 55, 5)) + + handler(NON_VOID_ACTION, (state, _payload) => state), +>handler : Symbol(handler, Decl(instantiateContextualTypes.ts, 42, 1)) +>NON_VOID_ACTION : Symbol(NON_VOID_ACTION, Decl(instantiateContextualTypes.ts, 59, 5)) +>state : Symbol(state, Decl(instantiateContextualTypes.ts, 64, 30)) +>_payload : Symbol(_payload, Decl(instantiateContextualTypes.ts, 64, 36)) +>state : Symbol(state, Decl(instantiateContextualTypes.ts, 64, 30)) + + handler(VOID_ACTION, state => state) +>handler : Symbol(handler, Decl(instantiateContextualTypes.ts, 42, 1)) +>VOID_ACTION : Symbol(VOID_ACTION, Decl(instantiateContextualTypes.ts, 60, 5)) +>state : Symbol(state, Decl(instantiateContextualTypes.ts, 65, 24)) +>state : Symbol(state, Decl(instantiateContextualTypes.ts, 65, 24)) + +) + +// #25814 + +type R = { +>R : Symbol(R, Decl(instantiateContextualTypes.ts, 66, 1)) + + a: (x: number) => void; +>a : Symbol(a, Decl(instantiateContextualTypes.ts, 70, 10)) +>x : Symbol(x, Decl(instantiateContextualTypes.ts, 71, 6)) + + b: (x: string) => void; +>b : Symbol(b, Decl(instantiateContextualTypes.ts, 71, 25)) +>x : Symbol(x, Decl(instantiateContextualTypes.ts, 72, 6)) + +}; + +type O = { +>O : Symbol(O, Decl(instantiateContextualTypes.ts, 73, 2)) + + on

(x: P, callback: R[P]): void; +>on : Symbol(on, Decl(instantiateContextualTypes.ts, 75, 10)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 76, 5)) +>R : Symbol(R, Decl(instantiateContextualTypes.ts, 66, 1)) +>x : Symbol(x, Decl(instantiateContextualTypes.ts, 76, 24)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 76, 5)) +>callback : Symbol(callback, Decl(instantiateContextualTypes.ts, 76, 29)) +>R : Symbol(R, Decl(instantiateContextualTypes.ts, 66, 1)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 76, 5)) + +}; + +declare var x: O; +>x : Symbol(x, Decl(instantiateContextualTypes.ts, 79, 11)) +>O : Symbol(O, Decl(instantiateContextualTypes.ts, 73, 2)) + +x.on('a', a => {}); +>x.on : Symbol(on, Decl(instantiateContextualTypes.ts, 75, 10)) +>x : Symbol(x, Decl(instantiateContextualTypes.ts, 79, 11)) +>on : Symbol(on, Decl(instantiateContextualTypes.ts, 75, 10)) +>a : Symbol(a, Decl(instantiateContextualTypes.ts, 80, 9)) + +// #29775 + +namespace N1 { +>N1 : Symbol(N1, Decl(instantiateContextualTypes.ts, 80, 19)) + +declare class Component

{ +>Component : Symbol(Component, Decl(instantiateContextualTypes.ts, 84, 14)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 86, 24)) + + constructor(props: P); +>props : Symbol(props, Decl(instantiateContextualTypes.ts, 87, 14)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 86, 24)) +} + +interface ComponentClass

{ +>ComponentClass : Symbol(ComponentClass, Decl(instantiateContextualTypes.ts, 88, 1)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 90, 25)) + + new (props: P): Component

; +>props : Symbol(props, Decl(instantiateContextualTypes.ts, 91, 7)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 90, 25)) +>Component : Symbol(Component, Decl(instantiateContextualTypes.ts, 84, 14)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 90, 25)) +} + +type CreateElementChildren

= +>CreateElementChildren : Symbol(CreateElementChildren, Decl(instantiateContextualTypes.ts, 92, 1)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 94, 27)) + + P extends { children?: infer C } +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 94, 27)) +>children : Symbol(children, Decl(instantiateContextualTypes.ts, 95, 13)) +>C : Symbol(C, Decl(instantiateContextualTypes.ts, 95, 30)) + + ? C extends any[] +>C : Symbol(C, Decl(instantiateContextualTypes.ts, 95, 30)) + + ? C +>C : Symbol(C, Decl(instantiateContextualTypes.ts, 95, 30)) + + : C[] +>C : Symbol(C, Decl(instantiateContextualTypes.ts, 95, 30)) + + : unknown; + +declare function createElement

( +>createElement : Symbol(createElement, Decl(instantiateContextualTypes.ts, 99, 12)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 101, 31)) + + type: ComponentClass

, +>type : Symbol(type, Decl(instantiateContextualTypes.ts, 101, 45)) +>ComponentClass : Symbol(ComponentClass, Decl(instantiateContextualTypes.ts, 88, 1)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 101, 31)) + + ...children: CreateElementChildren

+>children : Symbol(children, Decl(instantiateContextualTypes.ts, 102, 26)) +>CreateElementChildren : Symbol(CreateElementChildren, Decl(instantiateContextualTypes.ts, 92, 1)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 101, 31)) + +): any; + +declare function createElement2

( +>createElement2 : Symbol(createElement2, Decl(instantiateContextualTypes.ts, 104, 7)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 106, 32)) + + type: ComponentClass

, +>type : Symbol(type, Decl(instantiateContextualTypes.ts, 106, 46)) +>ComponentClass : Symbol(ComponentClass, Decl(instantiateContextualTypes.ts, 88, 1)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 106, 32)) + + child: CreateElementChildren

+>child : Symbol(child, Decl(instantiateContextualTypes.ts, 107, 26)) +>CreateElementChildren : Symbol(CreateElementChildren, Decl(instantiateContextualTypes.ts, 92, 1)) +>P : Symbol(P, Decl(instantiateContextualTypes.ts, 106, 32)) + +): any; + +class InferFunctionTypes extends Component<{children: (foo: number) => string}> {} +>InferFunctionTypes : Symbol(InferFunctionTypes, Decl(instantiateContextualTypes.ts, 109, 7)) +>Component : Symbol(Component, Decl(instantiateContextualTypes.ts, 84, 14)) +>children : Symbol(children, Decl(instantiateContextualTypes.ts, 111, 44)) +>foo : Symbol(foo, Decl(instantiateContextualTypes.ts, 111, 55)) + +createElement(InferFunctionTypes, (foo) => "" + foo); +>createElement : Symbol(createElement, Decl(instantiateContextualTypes.ts, 99, 12)) +>InferFunctionTypes : Symbol(InferFunctionTypes, Decl(instantiateContextualTypes.ts, 109, 7)) +>foo : Symbol(foo, Decl(instantiateContextualTypes.ts, 113, 35)) +>foo : Symbol(foo, Decl(instantiateContextualTypes.ts, 113, 35)) + +createElement2(InferFunctionTypes, [(foo) => "" + foo]); +>createElement2 : Symbol(createElement2, Decl(instantiateContextualTypes.ts, 104, 7)) +>InferFunctionTypes : Symbol(InferFunctionTypes, Decl(instantiateContextualTypes.ts, 109, 7)) +>foo : Symbol(foo, Decl(instantiateContextualTypes.ts, 115, 37)) +>foo : Symbol(foo, Decl(instantiateContextualTypes.ts, 115, 37)) + +} + +// #30341 + +type InnerBox = { +>InnerBox : Symbol(InnerBox, Decl(instantiateContextualTypes.ts, 117, 1)) +>T : Symbol(T, Decl(instantiateContextualTypes.ts, 121, 14)) + + value: T; +>value : Symbol(value, Decl(instantiateContextualTypes.ts, 121, 20)) +>T : Symbol(T, Decl(instantiateContextualTypes.ts, 121, 14)) +} + +type OuterBox = { +>OuterBox : Symbol(OuterBox, Decl(instantiateContextualTypes.ts, 123, 1)) +>T : Symbol(T, Decl(instantiateContextualTypes.ts, 125, 14)) + + inner: InnerBox +>inner : Symbol(inner, Decl(instantiateContextualTypes.ts, 125, 20)) +>InnerBox : Symbol(InnerBox, Decl(instantiateContextualTypes.ts, 117, 1)) +>T : Symbol(T, Decl(instantiateContextualTypes.ts, 125, 14)) + +}; + +type BoxConsumerFromOuterBox = +>BoxConsumerFromOuterBox : Symbol(BoxConsumerFromOuterBox, Decl(instantiateContextualTypes.ts, 127, 2)) +>T : Symbol(T, Decl(instantiateContextualTypes.ts, 129, 29)) + + T extends OuterBox ? +>T : Symbol(T, Decl(instantiateContextualTypes.ts, 129, 29)) +>OuterBox : Symbol(OuterBox, Decl(instantiateContextualTypes.ts, 123, 1)) +>U : Symbol(U, Decl(instantiateContextualTypes.ts, 130, 26)) + + (box: InnerBox) => void : +>box : Symbol(box, Decl(instantiateContextualTypes.ts, 131, 7)) +>InnerBox : Symbol(InnerBox, Decl(instantiateContextualTypes.ts, 117, 1)) +>U : Symbol(U, Decl(instantiateContextualTypes.ts, 130, 26)) + + never; + +declare function passContentsToFunc(outerBox: T, consumer: BoxConsumerFromOuterBox): void; +>passContentsToFunc : Symbol(passContentsToFunc, Decl(instantiateContextualTypes.ts, 132, 12)) +>T : Symbol(T, Decl(instantiateContextualTypes.ts, 134, 36)) +>outerBox : Symbol(outerBox, Decl(instantiateContextualTypes.ts, 134, 39)) +>T : Symbol(T, Decl(instantiateContextualTypes.ts, 134, 36)) +>consumer : Symbol(consumer, Decl(instantiateContextualTypes.ts, 134, 51)) +>BoxConsumerFromOuterBox : Symbol(BoxConsumerFromOuterBox, Decl(instantiateContextualTypes.ts, 127, 2)) +>T : Symbol(T, Decl(instantiateContextualTypes.ts, 134, 36)) + +declare const outerBoxOfString: OuterBox; +>outerBoxOfString : Symbol(outerBoxOfString, Decl(instantiateContextualTypes.ts, 136, 13)) +>OuterBox : Symbol(OuterBox, Decl(instantiateContextualTypes.ts, 123, 1)) + +passContentsToFunc(outerBoxOfString, box => box.value); +>passContentsToFunc : Symbol(passContentsToFunc, Decl(instantiateContextualTypes.ts, 132, 12)) +>outerBoxOfString : Symbol(outerBoxOfString, Decl(instantiateContextualTypes.ts, 136, 13)) +>box : Symbol(box, Decl(instantiateContextualTypes.ts, 138, 36)) +>box.value : Symbol(value, Decl(instantiateContextualTypes.ts, 121, 20)) +>box : Symbol(box, Decl(instantiateContextualTypes.ts, 138, 36)) +>value : Symbol(value, Decl(instantiateContextualTypes.ts, 121, 20)) + diff --git a/tests/baselines/reference/instantiateContextualTypes.types b/tests/baselines/reference/instantiateContextualTypes.types new file mode 100644 index 00000000000..0e755e82ed3 --- /dev/null +++ b/tests/baselines/reference/instantiateContextualTypes.types @@ -0,0 +1,328 @@ +=== tests/cases/compiler/instantiateContextualTypes.ts === +// #6611 + +export interface A { + value: a; +>value : a +} + +function fn(values: A, value: a) : void { +>fn : (values: A, value: a) => void +>values : A +>value : a +} + +declare let handlers: A<(value: number) => void>; +>handlers : A<(value: number) => void> +>value : number + +fn(handlers, value => alert(value)); +>fn(handlers, value => alert(value)) : void +>fn : (values: A, value: a) => void +>handlers : A<(value: number) => void> +>value => alert(value) : (value: number) => void +>value : number +>alert(value) : void +>alert : (message?: any) => void +>value : number + +// #21382 + +interface BaseProps { + initialValues: T; +>initialValues : T + + nextValues: (cur: T) => T; +>nextValues : (cur: T) => T +>cur : T +} +declare class Component

{ constructor(props: P); props: P; } +>Component : Component

+>props : P +>props : P + +declare class GenericComponent +>GenericComponent : GenericComponent + + extends Component> { +>Component : Component> + + iv: Values; +>iv : Values +} + +new GenericComponent({ initialValues: 12, nextValues: val => 12 }); +>new GenericComponent({ initialValues: 12, nextValues: val => 12 }) : GenericComponent<{ initialValues: number; nextValues: (val: number) => number; }, number> +>GenericComponent : typeof GenericComponent +>{ initialValues: 12, nextValues: val => 12 } : { initialValues: number; nextValues: (val: number) => number; } +>initialValues : number +>12 : 12 +>nextValues : (val: number) => number +>val => 12 : (val: number) => number +>val : number +>12 : 12 + +// #22149 + +declare function useStringOrNumber(t: T, useIt: T extends string ? ((s: string) => void) : ((n: number) => void)): void; +>useStringOrNumber : (t: T, useIt: T extends string ? (s: string) => void : (n: number) => void) => void +>t : T +>useIt : T extends string ? (s: string) => void : (n: number) => void +>s : string +>n : number + +useStringOrNumber("", foo => {}); +>useStringOrNumber("", foo => {}) : void +>useStringOrNumber : (t: T, useIt: T extends string ? (s: string) => void : (n: number) => void) => void +>"" : "" +>foo => {} : (foo: string) => void +>foo : string + +// #25299 + +type ActionType

= string & { attachPayloadTypeHack?: P & never } +>ActionType : ActionType

+>attachPayloadTypeHack : undefined + +type Handler = P extends void +>Handler : Handler + + ? (state: S) => S +>state : S + + : (state: S, payload: P) => S +>state : S +>payload : P + +interface ActionHandler { + actionType: ActionType

+>actionType : ActionType

+ + handler: Handler +>handler : Handler +} + +declare function handler(actionType: ActionType

, handler: Handler): ActionHandler +>handler : (actionType: ActionType

, handler: Handler) => ActionHandler +>actionType : ActionType

+>handler : Handler + +declare function createReducer( +>createReducer : (defaultState: S, ...actionHandlers: ActionHandler[]) => any + + defaultState: S, +>defaultState : S + + ...actionHandlers: ActionHandler[] +>actionHandlers : ActionHandler[] + + ): any + +interface AppState { + dummy: string +>dummy : string +} + +const defaultState: AppState = { +>defaultState : AppState +>{ dummy: ''} : { dummy: string; } + + dummy: '' +>dummy : string +>'' : "" +} + +const NON_VOID_ACTION: ActionType = 'NON_VOID_ACTION' +>NON_VOID_ACTION : ActionType +>'NON_VOID_ACTION' : "NON_VOID_ACTION" + + , VOID_ACTION: ActionType = 'VOID_ACTION' +>VOID_ACTION : ActionType +>'VOID_ACTION' : "VOID_ACTION" + +createReducer( +>createReducer( defaultState, handler(NON_VOID_ACTION, (state, _payload) => state), handler(VOID_ACTION, state => state)) : any +>createReducer : (defaultState: S, ...actionHandlers: ActionHandler[]) => any + + defaultState, +>defaultState : AppState + + handler(NON_VOID_ACTION, (state, _payload) => state), +>handler(NON_VOID_ACTION, (state, _payload) => state) : ActionHandler +>handler : (actionType: ActionType

, handler: Handler) => ActionHandler +>NON_VOID_ACTION : ActionType +>(state, _payload) => state : (state: AppState, _payload: number) => AppState +>state : AppState +>_payload : number +>state : AppState + + handler(VOID_ACTION, state => state) +>handler(VOID_ACTION, state => state) : ActionHandler +>handler : (actionType: ActionType

, handler: Handler) => ActionHandler +>VOID_ACTION : ActionType +>state => state : (state: AppState) => AppState +>state : AppState +>state : AppState + +) + +// #25814 + +type R = { +>R : R + + a: (x: number) => void; +>a : (x: number) => void +>x : number + + b: (x: string) => void; +>b : (x: string) => void +>x : string + +}; + +type O = { +>O : O + + on

(x: P, callback: R[P]): void; +>on :

(x: P, callback: R[P]) => void +>x : P +>callback : R[P] + +}; + +declare var x: O; +>x : O + +x.on('a', a => {}); +>x.on('a', a => {}) : void +>x.on :

(x: P, callback: R[P]) => void +>x : O +>on :

(x: P, callback: R[P]) => void +>'a' : "a" +>a => {} : (a: number) => void +>a : number + +// #29775 + +namespace N1 { +>N1 : typeof N1 + +declare class Component

{ +>Component : Component

+ + constructor(props: P); +>props : P +} + +interface ComponentClass

{ + new (props: P): Component

; +>props : P +} + +type CreateElementChildren

= +>CreateElementChildren : P extends { children?: infer C | undefined; } ? C extends any[] ? C : C[] : unknown + + P extends { children?: infer C } +>children : C | undefined + + ? C extends any[] + ? C + : C[] + : unknown; + +declare function createElement

( +>createElement :

(type: ComponentClass

, ...children: P extends { children?: infer C | undefined; } ? C extends any[] ? C : C[] : unknown) => any + + type: ComponentClass

, +>type : ComponentClass

+ + ...children: CreateElementChildren

+>children : P extends { children?: infer C | undefined; } ? C extends any[] ? C : C[] : unknown + +): any; + +declare function createElement2

( +>createElement2 :

(type: ComponentClass

, child: P extends { children?: infer C | undefined; } ? C extends any[] ? C : C[] : unknown) => any + + type: ComponentClass

, +>type : ComponentClass

+ + child: CreateElementChildren

+>child : P extends { children?: infer C | undefined; } ? C extends any[] ? C : C[] : unknown + +): any; + +class InferFunctionTypes extends Component<{children: (foo: number) => string}> {} +>InferFunctionTypes : InferFunctionTypes +>Component : Component<{ children: (foo: number) => string; }> +>children : (foo: number) => string +>foo : number + +createElement(InferFunctionTypes, (foo) => "" + foo); +>createElement(InferFunctionTypes, (foo) => "" + foo) : any +>createElement :

(type: ComponentClass

, ...children: P extends { children?: infer C | undefined; } ? C extends any[] ? C : C[] : unknown) => any +>InferFunctionTypes : typeof InferFunctionTypes +>(foo) => "" + foo : (foo: number) => string +>foo : number +>"" + foo : string +>"" : "" +>foo : number + +createElement2(InferFunctionTypes, [(foo) => "" + foo]); +>createElement2(InferFunctionTypes, [(foo) => "" + foo]) : any +>createElement2 :

(type: ComponentClass

, child: P extends { children?: infer C | undefined; } ? C extends any[] ? C : C[] : unknown) => any +>InferFunctionTypes : typeof InferFunctionTypes +>[(foo) => "" + foo] : ((foo: number) => string)[] +>(foo) => "" + foo : (foo: number) => string +>foo : number +>"" + foo : string +>"" : "" +>foo : number + +} + +// #30341 + +type InnerBox = { +>InnerBox : InnerBox + + value: T; +>value : T +} + +type OuterBox = { +>OuterBox : OuterBox + + inner: InnerBox +>inner : InnerBox + +}; + +type BoxConsumerFromOuterBox = +>BoxConsumerFromOuterBox : BoxConsumerFromOuterBox + + T extends OuterBox ? + (box: InnerBox) => void : +>box : InnerBox + + never; + +declare function passContentsToFunc(outerBox: T, consumer: BoxConsumerFromOuterBox): void; +>passContentsToFunc : (outerBox: T, consumer: BoxConsumerFromOuterBox) => void +>outerBox : T +>consumer : BoxConsumerFromOuterBox + +declare const outerBoxOfString: OuterBox; +>outerBoxOfString : OuterBox + +passContentsToFunc(outerBoxOfString, box => box.value); +>passContentsToFunc(outerBoxOfString, box => box.value) : void +>passContentsToFunc : (outerBox: T, consumer: BoxConsumerFromOuterBox) => void +>outerBoxOfString : OuterBox +>box => box.value : (box: InnerBox) => string +>box : InnerBox +>box.value : string +>box : InnerBox +>value : string +