50 lines
1.7 KiB
Text
50 lines
1.7 KiB
Text
=== tests/cases/conformance/expressions/functions/contextuallyTypedFunctionExpressionsAndReturnAnnotations.ts ===
|
|
declare function foo(x: (y: string) => (y2: number) => void);
|
|
>foo : (x: (y: string) => (y2: number) => void) => any
|
|
>x : (y: string) => (y2: number) => void
|
|
>y : string
|
|
>y2 : number
|
|
|
|
// Contextually type the parameter even if there is a return annotation
|
|
foo((y): (y2: number) => void => {
|
|
>foo((y): (y2: number) => void => { var z = y.charAt(0); // Should be string return null;}) : any
|
|
>foo : (x: (y: string) => (y2: number) => void) => any
|
|
>(y): (y2: number) => void => { var z = y.charAt(0); // Should be string return null;} : (y: string) => (y2: number) => void
|
|
>y : string
|
|
>y2 : number
|
|
|
|
var z = y.charAt(0); // Should be string
|
|
>z : string
|
|
>y.charAt(0) : string
|
|
>y.charAt : (pos: number) => string
|
|
>y : string
|
|
>charAt : (pos: number) => string
|
|
>0 : number
|
|
|
|
return null;
|
|
>null : null
|
|
|
|
});
|
|
|
|
foo((y: string) => {
|
|
>foo((y: string) => { return y2 => { var z = y2.toFixed(); // Should be string return 0; };}) : any
|
|
>foo : (x: (y: string) => (y2: number) => void) => any
|
|
>(y: string) => { return y2 => { var z = y2.toFixed(); // Should be string return 0; };} : (y: string) => (y2: number) => number
|
|
>y : string
|
|
|
|
return y2 => {
|
|
>y2 => { var z = y2.toFixed(); // Should be string return 0; } : (y2: number) => number
|
|
>y2 : number
|
|
|
|
var z = y2.toFixed(); // Should be string
|
|
>z : string
|
|
>y2.toFixed() : string
|
|
>y2.toFixed : (fractionDigits?: number) => string
|
|
>y2 : number
|
|
>toFixed : (fractionDigits?: number) => string
|
|
|
|
return 0;
|
|
>0 : number
|
|
|
|
};
|
|
});
|