mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Added tests for contextual typing on parenthesized expressions, added case for tagged templates.
This commit is contained in:
parent
55628109c8
commit
d5f02813f0
52
tests/baselines/reference/parenthesizedContexualTyping1.js
Normal file
52
tests/baselines/reference/parenthesizedContexualTyping1.js
Normal file
@ -0,0 +1,52 @@
|
||||
//// [parenthesizedContexualTyping1.ts]
|
||||
|
||||
function fun<T>(g: (x: T) => T, x: T): T;
|
||||
function fun<T>(g: (x: T) => T, h: (y: T) => T, x: T): T;
|
||||
function fun<T>(g: (x: T) => T, x: T): T {
|
||||
return g(x);
|
||||
}
|
||||
|
||||
var a = fun(x => x, 10);
|
||||
var b = fun((x => x), 10);
|
||||
var c = fun(((x => x)), 10);
|
||||
var d = fun((((x => x))), 10);
|
||||
|
||||
var e = fun(x => x, x => x, 10);
|
||||
var f = fun((x => x), (x => x), 10);
|
||||
var g = fun(((x => x)), ((x => x)), 10);
|
||||
var h = fun((((x => x))), ((x => x)), 10);
|
||||
|
||||
// Ternaries in parens
|
||||
var i = fun((Math.random() < 0.5 ? x => x : x => undefined), 10);
|
||||
var j = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10);
|
||||
var k = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10);
|
||||
var l = fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10);
|
||||
|
||||
var lambda1: (x: number) => number = x => x;
|
||||
var lambda2: (x: number) => number = (x => x);
|
||||
|
||||
type ObjType = { x: (p: number) => string; y: (p: string) => number };
|
||||
var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) };
|
||||
var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) });
|
||||
|
||||
//// [parenthesizedContexualTyping1.js]
|
||||
function fun(g, x) {
|
||||
return g(x);
|
||||
}
|
||||
var a = fun(function (x) { return x; }, 10);
|
||||
var b = fun((function (x) { return x; }), 10);
|
||||
var c = fun(((function (x) { return x; })), 10);
|
||||
var d = fun((((function (x) { return x; }))), 10);
|
||||
var e = fun(function (x) { return x; }, function (x) { return x; }, 10);
|
||||
var f = fun((function (x) { return x; }), (function (x) { return x; }), 10);
|
||||
var g = fun(((function (x) { return x; })), ((function (x) { return x; })), 10);
|
||||
var h = fun((((function (x) { return x; }))), ((function (x) { return x; })), 10);
|
||||
// Ternaries in parens
|
||||
var i = fun((Math.random() < 0.5 ? function (x) { return x; } : function (x) { return undefined; }), 10);
|
||||
var j = fun((Math.random() < 0.5 ? (function (x) { return x; }) : (function (x) { return undefined; })), 10);
|
||||
var k = fun((Math.random() < 0.5 ? (function (x) { return x; }) : (function (x) { return undefined; })), function (x) { return x; }, 10);
|
||||
var l = fun(((Math.random() < 0.5 ? ((function (x) { return x; })) : ((function (x) { return undefined; })))), ((function (x) { return x; })), 10);
|
||||
var lambda1 = function (x) { return x; };
|
||||
var lambda2 = (function (x) { return x; });
|
||||
var obj1 = { x: function (x) { return (x, undefined); }, y: function (y) { return (y, undefined); } };
|
||||
var obj2 = ({ x: function (x) { return (x, undefined); }, y: function (y) { return (y, undefined); } });
|
||||
289
tests/baselines/reference/parenthesizedContexualTyping1.types
Normal file
289
tests/baselines/reference/parenthesizedContexualTyping1.types
Normal file
@ -0,0 +1,289 @@
|
||||
=== tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping1.ts ===
|
||||
|
||||
function fun<T>(g: (x: T) => T, x: T): T;
|
||||
>fun : { <T>(g: (x: T) => T, x: T): T; <T>(g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>T : T
|
||||
>g : (x: T) => T
|
||||
>x : T
|
||||
>T : T
|
||||
>T : T
|
||||
>x : T
|
||||
>T : T
|
||||
>T : T
|
||||
|
||||
function fun<T>(g: (x: T) => T, h: (y: T) => T, x: T): T;
|
||||
>fun : { <T>(g: (x: T) => T, x: T): T; <T>(g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>T : T
|
||||
>g : (x: T) => T
|
||||
>x : T
|
||||
>T : T
|
||||
>T : T
|
||||
>h : (y: T) => T
|
||||
>y : T
|
||||
>T : T
|
||||
>T : T
|
||||
>x : T
|
||||
>T : T
|
||||
>T : T
|
||||
|
||||
function fun<T>(g: (x: T) => T, x: T): T {
|
||||
>fun : { <T>(g: (x: T) => T, x: T): T; <T>(g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>T : T
|
||||
>g : (x: T) => T
|
||||
>x : T
|
||||
>T : T
|
||||
>T : T
|
||||
>x : T
|
||||
>T : T
|
||||
>T : T
|
||||
|
||||
return g(x);
|
||||
>g(x) : T
|
||||
>g : (x: T) => T
|
||||
>x : T
|
||||
}
|
||||
|
||||
var a = fun(x => x, 10);
|
||||
>a : number
|
||||
>fun(x => x, 10) : number
|
||||
>fun : { <T>(g: (x: T) => T, x: T): T; <T>(g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>x => x : (x: number) => number
|
||||
>x : number
|
||||
>x : number
|
||||
|
||||
var b = fun((x => x), 10);
|
||||
>b : any
|
||||
>fun((x => x), 10) : any
|
||||
>fun : { <T>(g: (x: T) => T, x: T): T; <T>(g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
|
||||
var c = fun(((x => x)), 10);
|
||||
>c : any
|
||||
>fun(((x => x)), 10) : any
|
||||
>fun : { <T>(g: (x: T) => T, x: T): T; <T>(g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>((x => x)) : (x: any) => any
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
|
||||
var d = fun((((x => x))), 10);
|
||||
>d : any
|
||||
>fun((((x => x))), 10) : any
|
||||
>fun : { <T>(g: (x: T) => T, x: T): T; <T>(g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>(((x => x))) : (x: any) => any
|
||||
>((x => x)) : (x: any) => any
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
|
||||
var e = fun(x => x, x => x, 10);
|
||||
>e : number
|
||||
>fun(x => x, x => x, 10) : number
|
||||
>fun : { <T>(g: (x: T) => T, x: T): T; <T>(g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>x => x : (x: number) => number
|
||||
>x : number
|
||||
>x : number
|
||||
>x => x : (x: number) => number
|
||||
>x : number
|
||||
>x : number
|
||||
|
||||
var f = fun((x => x), (x => x), 10);
|
||||
>f : any
|
||||
>fun((x => x), (x => x), 10) : any
|
||||
>fun : { <T>(g: (x: T) => T, x: T): T; <T>(g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
|
||||
var g = fun(((x => x)), ((x => x)), 10);
|
||||
>g : any
|
||||
>fun(((x => x)), ((x => x)), 10) : any
|
||||
>fun : { <T>(g: (x: T) => T, x: T): T; <T>(g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>((x => x)) : (x: any) => any
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
>((x => x)) : (x: any) => any
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
|
||||
var h = fun((((x => x))), ((x => x)), 10);
|
||||
>h : any
|
||||
>fun((((x => x))), ((x => x)), 10) : any
|
||||
>fun : { <T>(g: (x: T) => T, x: T): T; <T>(g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>(((x => x))) : (x: any) => any
|
||||
>((x => x)) : (x: any) => any
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
>((x => x)) : (x: any) => any
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
|
||||
// Ternaries in parens
|
||||
var i = fun((Math.random() < 0.5 ? x => x : x => undefined), 10);
|
||||
>i : any
|
||||
>fun((Math.random() < 0.5 ? x => x : x => undefined), 10) : any
|
||||
>fun : { <T>(g: (x: T) => T, x: T): T; <T>(g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>(Math.random() < 0.5 ? x => x : x => undefined) : (x: any) => any
|
||||
>Math.random() < 0.5 ? x => x : x => undefined : (x: any) => any
|
||||
>Math.random() < 0.5 : boolean
|
||||
>Math.random() : number
|
||||
>Math.random : () => number
|
||||
>Math : Math
|
||||
>random : () => number
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
>x => undefined : (x: any) => any
|
||||
>x : any
|
||||
>undefined : undefined
|
||||
|
||||
var j = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10);
|
||||
>j : any
|
||||
>fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10) : any
|
||||
>fun : { <T>(g: (x: T) => T, x: T): T; <T>(g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>(Math.random() < 0.5 ? (x => x) : (x => undefined)) : (x: any) => any
|
||||
>Math.random() < 0.5 ? (x => x) : (x => undefined) : (x: any) => any
|
||||
>Math.random() < 0.5 : boolean
|
||||
>Math.random() : number
|
||||
>Math.random : () => number
|
||||
>Math : Math
|
||||
>random : () => number
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
>(x => undefined) : (x: any) => any
|
||||
>x => undefined : (x: any) => any
|
||||
>x : any
|
||||
>undefined : undefined
|
||||
|
||||
var k = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10);
|
||||
>k : any
|
||||
>fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10) : any
|
||||
>fun : { <T>(g: (x: T) => T, x: T): T; <T>(g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>(Math.random() < 0.5 ? (x => x) : (x => undefined)) : (x: any) => any
|
||||
>Math.random() < 0.5 ? (x => x) : (x => undefined) : (x: any) => any
|
||||
>Math.random() < 0.5 : boolean
|
||||
>Math.random() : number
|
||||
>Math.random : () => number
|
||||
>Math : Math
|
||||
>random : () => number
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
>(x => undefined) : (x: any) => any
|
||||
>x => undefined : (x: any) => any
|
||||
>x : any
|
||||
>undefined : undefined
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
|
||||
var l = fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10);
|
||||
>l : any
|
||||
>fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10) : any
|
||||
>fun : { <T>(g: (x: T) => T, x: T): T; <T>(g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))) : (x: any) => any
|
||||
>(Math.random() < 0.5 ? ((x => x)) : ((x => undefined))) : (x: any) => any
|
||||
>Math.random() < 0.5 ? ((x => x)) : ((x => undefined)) : (x: any) => any
|
||||
>Math.random() < 0.5 : boolean
|
||||
>Math.random() : number
|
||||
>Math.random : () => number
|
||||
>Math : Math
|
||||
>random : () => number
|
||||
>((x => x)) : (x: any) => any
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
>((x => undefined)) : (x: any) => any
|
||||
>(x => undefined) : (x: any) => any
|
||||
>x => undefined : (x: any) => any
|
||||
>x : any
|
||||
>undefined : undefined
|
||||
>((x => x)) : (x: any) => any
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
|
||||
var lambda1: (x: number) => number = x => x;
|
||||
>lambda1 : (x: number) => number
|
||||
>x : number
|
||||
>x => x : (x: number) => number
|
||||
>x : number
|
||||
>x : number
|
||||
|
||||
var lambda2: (x: number) => number = (x => x);
|
||||
>lambda2 : (x: number) => number
|
||||
>x : number
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
|
||||
type ObjType = { x: (p: number) => string; y: (p: string) => number };
|
||||
>ObjType : { x: (p: number) => string; y: (p: string) => number; }
|
||||
>x : (p: number) => string
|
||||
>p : number
|
||||
>y : (p: string) => number
|
||||
>p : string
|
||||
|
||||
var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) };
|
||||
>obj1 : { x: (p: number) => string; y: (p: string) => number; }
|
||||
>ObjType : { x: (p: number) => string; y: (p: string) => number; }
|
||||
>{ x: x => (x, undefined), y: y => (y, undefined) } : { x: (x: number) => any; y: (y: string) => any; }
|
||||
>x : (x: number) => any
|
||||
>x => (x, undefined) : (x: number) => any
|
||||
>x : number
|
||||
>(x, undefined) : undefined
|
||||
>x, undefined : undefined
|
||||
>x : number
|
||||
>undefined : undefined
|
||||
>y : (y: string) => any
|
||||
>y => (y, undefined) : (y: string) => any
|
||||
>y : string
|
||||
>(y, undefined) : undefined
|
||||
>y, undefined : undefined
|
||||
>y : string
|
||||
>undefined : undefined
|
||||
|
||||
var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) });
|
||||
>obj2 : { x: (p: number) => string; y: (p: string) => number; }
|
||||
>ObjType : { x: (p: number) => string; y: (p: string) => number; }
|
||||
>({ x: x => (x, undefined), y: y => (y, undefined) }) : { x: (x: any) => any; y: (y: any) => any; }
|
||||
>{ x: x => (x, undefined), y: y => (y, undefined) } : { x: (x: any) => any; y: (y: any) => any; }
|
||||
>x : (x: any) => any
|
||||
>x => (x, undefined) : (x: any) => any
|
||||
>x : any
|
||||
>(x, undefined) : undefined
|
||||
>x, undefined : undefined
|
||||
>x : any
|
||||
>undefined : undefined
|
||||
>y : (y: any) => any
|
||||
>y => (y, undefined) : (y: any) => any
|
||||
>y : any
|
||||
>(y, undefined) : undefined
|
||||
>y, undefined : undefined
|
||||
>y : any
|
||||
>undefined : undefined
|
||||
|
||||
@ -0,0 +1,86 @@
|
||||
tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(15,21): error TS2347: Untyped function calls may not accept type arguments.
|
||||
tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(16,22): error TS2347: Untyped function calls may not accept type arguments.
|
||||
tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(17,23): error TS2347: Untyped function calls may not accept type arguments.
|
||||
tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(20,21): error TS2347: Untyped function calls may not accept type arguments.
|
||||
tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(20,64): error TS2347: Untyped function calls may not accept type arguments.
|
||||
tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(21,22): error TS2347: Untyped function calls may not accept type arguments.
|
||||
tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(21,67): error TS2347: Untyped function calls may not accept type arguments.
|
||||
tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(22,23): error TS2347: Untyped function calls may not accept type arguments.
|
||||
tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(22,69): error TS2347: Untyped function calls may not accept type arguments.
|
||||
tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(25,43): error TS2347: Untyped function calls may not accept type arguments.
|
||||
tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(26,44): error TS2347: Untyped function calls may not accept type arguments.
|
||||
tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(27,44): error TS2347: Untyped function calls may not accept type arguments.
|
||||
tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(28,46): error TS2347: Untyped function calls may not accept type arguments.
|
||||
tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(28,114): error TS2347: Untyped function calls may not accept type arguments.
|
||||
tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(30,45): error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts(31,46): error TS2347: Untyped function calls may not accept type arguments.
|
||||
|
||||
|
||||
==== tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping2.ts (16 errors) ====
|
||||
// These tests ensure that in cases where it may *appear* that a value has a type,
|
||||
// they actually are properly being contextually typed. The way we test this is
|
||||
// that we invoke contextually typed arguments with type arguments.
|
||||
// Since 'any' cannot be invoked with type arguments, we should get errors back.
|
||||
|
||||
type FuncType = (x: <T>(p: T) => T) => typeof x;
|
||||
|
||||
function fun<T>(f: FuncType, x: T): T;
|
||||
function fun<T>(f: FuncType, g: FuncType, x: T): T;
|
||||
function fun<T>(...rest: any[]): T {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var a = fun(x => { x<number>(undefined); return x; }, 10);
|
||||
var b = fun((x => { x<number>(undefined); return x; }), 10);
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2347: Untyped function calls may not accept type arguments.
|
||||
var c = fun(((x => { x<number>(undefined); return x; })), 10);
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2347: Untyped function calls may not accept type arguments.
|
||||
var d = fun((((x => { x<number>(undefined); return x; }))), 10);
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2347: Untyped function calls may not accept type arguments.
|
||||
|
||||
var e = fun(x => { x<number>(undefined); return x; }, x => { x<number>(undefined); return x; }, 10);
|
||||
var f = fun((x => { x<number>(undefined); return x; }),(x => { x<number>(undefined); return x; }), 10);
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2347: Untyped function calls may not accept type arguments.
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2347: Untyped function calls may not accept type arguments.
|
||||
var g = fun(((x => { x<number>(undefined); return x; })),((x => { x<number>(undefined); return x; })), 10);
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2347: Untyped function calls may not accept type arguments.
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2347: Untyped function calls may not accept type arguments.
|
||||
var h = fun((((x => { x<number>(undefined); return x; }))),((x => { x<number>(undefined); return x; })), 10);
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2347: Untyped function calls may not accept type arguments.
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2347: Untyped function calls may not accept type arguments.
|
||||
|
||||
// Ternaries in parens
|
||||
var i = fun((Math.random() < 0.5 ? x => { x<number>(undefined); return x; } : x => undefined), 10);
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2347: Untyped function calls may not accept type arguments.
|
||||
var j = fun((Math.random() < 0.5 ? (x => { x<number>(undefined); return x; }) : (x => undefined)), 10);
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2347: Untyped function calls may not accept type arguments.
|
||||
var k = fun((Math.random() < 0.5 ? (x => { x<number>(undefined); return x; }) : (x => undefined)), x => { x<number>(undefined); return x; }, 10);
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2347: Untyped function calls may not accept type arguments.
|
||||
var l = fun(((Math.random() < 0.5 ? ((x => { x<number>(undefined); return x; })) : ((x => undefined)))),((x => { x<number>(undefined); return x; })), 10);
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2347: Untyped function calls may not accept type arguments.
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2347: Untyped function calls may not accept type arguments.
|
||||
|
||||
var lambda1: (x: number) => number = x => { x<number>(undefined); return x; };
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2349: Cannot invoke an expression whose type lacks a call signature.
|
||||
var lambda2: (x: number) => number = (x => { x<number>(undefined); return x; });
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2347: Untyped function calls may not accept type arguments.
|
||||
|
||||
type ObjType = { x: (p: number) => string; y: (p: string) => number };
|
||||
var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) };
|
||||
var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) });
|
||||
126
tests/baselines/reference/parenthesizedContexualTyping2.js
Normal file
126
tests/baselines/reference/parenthesizedContexualTyping2.js
Normal file
@ -0,0 +1,126 @@
|
||||
//// [parenthesizedContexualTyping2.ts]
|
||||
// These tests ensure that in cases where it may *appear* that a value has a type,
|
||||
// they actually are properly being contextually typed. The way we test this is
|
||||
// that we invoke contextually typed arguments with type arguments.
|
||||
// Since 'any' cannot be invoked with type arguments, we should get errors back.
|
||||
|
||||
type FuncType = (x: <T>(p: T) => T) => typeof x;
|
||||
|
||||
function fun<T>(f: FuncType, x: T): T;
|
||||
function fun<T>(f: FuncType, g: FuncType, x: T): T;
|
||||
function fun<T>(...rest: any[]): T {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var a = fun(x => { x<number>(undefined); return x; }, 10);
|
||||
var b = fun((x => { x<number>(undefined); return x; }), 10);
|
||||
var c = fun(((x => { x<number>(undefined); return x; })), 10);
|
||||
var d = fun((((x => { x<number>(undefined); return x; }))), 10);
|
||||
|
||||
var e = fun(x => { x<number>(undefined); return x; }, x => { x<number>(undefined); return x; }, 10);
|
||||
var f = fun((x => { x<number>(undefined); return x; }),(x => { x<number>(undefined); return x; }), 10);
|
||||
var g = fun(((x => { x<number>(undefined); return x; })),((x => { x<number>(undefined); return x; })), 10);
|
||||
var h = fun((((x => { x<number>(undefined); return x; }))),((x => { x<number>(undefined); return x; })), 10);
|
||||
|
||||
// Ternaries in parens
|
||||
var i = fun((Math.random() < 0.5 ? x => { x<number>(undefined); return x; } : x => undefined), 10);
|
||||
var j = fun((Math.random() < 0.5 ? (x => { x<number>(undefined); return x; }) : (x => undefined)), 10);
|
||||
var k = fun((Math.random() < 0.5 ? (x => { x<number>(undefined); return x; }) : (x => undefined)), x => { x<number>(undefined); return x; }, 10);
|
||||
var l = fun(((Math.random() < 0.5 ? ((x => { x<number>(undefined); return x; })) : ((x => undefined)))),((x => { x<number>(undefined); return x; })), 10);
|
||||
|
||||
var lambda1: (x: number) => number = x => { x<number>(undefined); return x; };
|
||||
var lambda2: (x: number) => number = (x => { x<number>(undefined); return x; });
|
||||
|
||||
type ObjType = { x: (p: number) => string; y: (p: string) => number };
|
||||
var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) };
|
||||
var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) });
|
||||
|
||||
//// [parenthesizedContexualTyping2.js]
|
||||
// These tests ensure that in cases where it may *appear* that a value has a type,
|
||||
// they actually are properly being contextually typed. The way we test this is
|
||||
// that we invoke contextually typed arguments with type arguments.
|
||||
// Since 'any' cannot be invoked with type arguments, we should get errors back.
|
||||
function fun() {
|
||||
var rest = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
rest[_i - 0] = arguments[_i];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
var a = fun(function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
}, 10);
|
||||
var b = fun((function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
}), 10);
|
||||
var c = fun(((function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
})), 10);
|
||||
var d = fun((((function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
}))), 10);
|
||||
var e = fun(function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
}, function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
}, 10);
|
||||
var f = fun((function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
}), (function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
}), 10);
|
||||
var g = fun(((function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
})), ((function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
})), 10);
|
||||
var h = fun((((function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
}))), ((function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
})), 10);
|
||||
// Ternaries in parens
|
||||
var i = fun((Math.random() < 0.5 ? function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
} : function (x) { return undefined; }), 10);
|
||||
var j = fun((Math.random() < 0.5 ? (function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
}) : (function (x) { return undefined; })), 10);
|
||||
var k = fun((Math.random() < 0.5 ? (function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
}) : (function (x) { return undefined; })), function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
}, 10);
|
||||
var l = fun(((Math.random() < 0.5 ? ((function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
})) : ((function (x) { return undefined; })))), ((function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
})), 10);
|
||||
var lambda1 = function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
};
|
||||
var lambda2 = (function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
});
|
||||
var obj1 = { x: function (x) { return (x, undefined); }, y: function (y) { return (y, undefined); } };
|
||||
var obj2 = ({ x: function (x) { return (x, undefined); }, y: function (y) { return (y, undefined); } });
|
||||
35
tests/baselines/reference/parenthesizedContexualTyping3.js
Normal file
35
tests/baselines/reference/parenthesizedContexualTyping3.js
Normal file
@ -0,0 +1,35 @@
|
||||
//// [parenthesizedContexualTyping3.ts]
|
||||
|
||||
// Contextual typing for parenthesized substitution expressions in tagged templates.
|
||||
|
||||
/**
|
||||
* tempFun - Can't have fun for too long.
|
||||
*/
|
||||
function tempFun<T>(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T;
|
||||
function tempFun<T>(tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T;
|
||||
function tempFun<T>(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T {
|
||||
return g(x);
|
||||
}
|
||||
|
||||
var a = tempFun `${ x => x } ${ 10 }`
|
||||
var b = tempFun `${ (x => x) } ${ 10 }`
|
||||
var c = tempFun `${ ((x => x)) } ${ 10 }`
|
||||
var d = tempFun `${ x => x } ${ x => x } ${ 10 }`
|
||||
var e = tempFun `${ x => x } ${ (x => x) } ${ 10 }`
|
||||
var f = tempFun `${ x => x } ${ ((x => x)) } ${ 10 }`
|
||||
var g = tempFun `${ (x => x) } ${ (((x => x))) } ${ 10 }`
|
||||
var h = tempFun `${ (x => x) } ${ (((x => x))) } ${ undefined }`
|
||||
|
||||
//// [parenthesizedContexualTyping3.js]
|
||||
// Contextual typing for parenthesized substitution expressions in tagged templates.
|
||||
function tempFun(tempStrs, g, x) {
|
||||
return g(x);
|
||||
}
|
||||
var a = tempFun `${function (x) { return x; }} ${10}`;
|
||||
var b = tempFun `${(function (x) { return x; })} ${10}`;
|
||||
var c = tempFun `${((function (x) { return x; }))} ${10}`;
|
||||
var d = tempFun `${function (x) { return x; }} ${function (x) { return x; }} ${10}`;
|
||||
var e = tempFun `${function (x) { return x; }} ${(function (x) { return x; })} ${10}`;
|
||||
var f = tempFun `${function (x) { return x; }} ${((function (x) { return x; }))} ${10}`;
|
||||
var g = tempFun `${(function (x) { return x; })} ${(((function (x) { return x; })))} ${10}`;
|
||||
var h = tempFun `${(function (x) { return x; })} ${(((function (x) { return x; })))} ${undefined}`;
|
||||
142
tests/baselines/reference/parenthesizedContexualTyping3.types
Normal file
142
tests/baselines/reference/parenthesizedContexualTyping3.types
Normal file
@ -0,0 +1,142 @@
|
||||
=== tests/cases/conformance/expressions/contextualTyping/parenthesizedContexualTyping3.ts ===
|
||||
|
||||
// Contextual typing for parenthesized substitution expressions in tagged templates.
|
||||
|
||||
/**
|
||||
* tempFun - Can't have fun for too long.
|
||||
*/
|
||||
function tempFun<T>(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T;
|
||||
>tempFun : { <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>T : T
|
||||
>tempStrs : TemplateStringsArray
|
||||
>TemplateStringsArray : TemplateStringsArray
|
||||
>g : (x: T) => T
|
||||
>x : T
|
||||
>T : T
|
||||
>T : T
|
||||
>x : T
|
||||
>T : T
|
||||
>T : T
|
||||
|
||||
function tempFun<T>(tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T;
|
||||
>tempFun : { <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>T : T
|
||||
>tempStrs : TemplateStringsArray
|
||||
>TemplateStringsArray : TemplateStringsArray
|
||||
>g : (x: T) => T
|
||||
>x : T
|
||||
>T : T
|
||||
>T : T
|
||||
>h : (y: T) => T
|
||||
>y : T
|
||||
>T : T
|
||||
>T : T
|
||||
>x : T
|
||||
>T : T
|
||||
>T : T
|
||||
|
||||
function tempFun<T>(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T {
|
||||
>tempFun : { <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>T : T
|
||||
>tempStrs : TemplateStringsArray
|
||||
>TemplateStringsArray : TemplateStringsArray
|
||||
>g : (x: T) => T
|
||||
>x : T
|
||||
>T : T
|
||||
>T : T
|
||||
>x : T
|
||||
>T : T
|
||||
>T : T
|
||||
|
||||
return g(x);
|
||||
>g(x) : T
|
||||
>g : (x: T) => T
|
||||
>x : T
|
||||
}
|
||||
|
||||
var a = tempFun `${ x => x } ${ 10 }`
|
||||
>a : number
|
||||
>tempFun : { <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>x => x : (x: number) => number
|
||||
>x : number
|
||||
>x : number
|
||||
|
||||
var b = tempFun `${ (x => x) } ${ 10 }`
|
||||
>b : any
|
||||
>tempFun : { <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
|
||||
var c = tempFun `${ ((x => x)) } ${ 10 }`
|
||||
>c : any
|
||||
>tempFun : { <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>((x => x)) : (x: any) => any
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
|
||||
var d = tempFun `${ x => x } ${ x => x } ${ 10 }`
|
||||
>d : number
|
||||
>tempFun : { <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>x => x : (x: number) => number
|
||||
>x : number
|
||||
>x : number
|
||||
>x => x : (x: number) => number
|
||||
>x : number
|
||||
>x : number
|
||||
|
||||
var e = tempFun `${ x => x } ${ (x => x) } ${ 10 }`
|
||||
>e : any
|
||||
>tempFun : { <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
|
||||
var f = tempFun `${ x => x } ${ ((x => x)) } ${ 10 }`
|
||||
>f : any
|
||||
>tempFun : { <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
>((x => x)) : (x: any) => any
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
|
||||
var g = tempFun `${ (x => x) } ${ (((x => x))) } ${ 10 }`
|
||||
>g : any
|
||||
>tempFun : { <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
>(((x => x))) : (x: any) => any
|
||||
>((x => x)) : (x: any) => any
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
|
||||
var h = tempFun `${ (x => x) } ${ (((x => x))) } ${ undefined }`
|
||||
>h : any
|
||||
>tempFun : { <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T; <T>(tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T; }
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
>(((x => x))) : (x: any) => any
|
||||
>((x => x)) : (x: any) => any
|
||||
>(x => x) : (x: any) => any
|
||||
>x => x : (x: any) => any
|
||||
>x : any
|
||||
>x : any
|
||||
>undefined : undefined
|
||||
|
||||
@ -12,6 +12,7 @@ function tempTag1<T>(...rest: any[]): T {
|
||||
// Otherwise, the arrow functions' parameters will be typed as 'any',
|
||||
// and it is an error to invoke an any-typed value with type arguments,
|
||||
// so this test will error.
|
||||
tempTag1 `${ x => { x<number>(undefined); return x; } }${ 10 }`;
|
||||
tempTag1 `${ x => { x<number>(undefined); return x; } }${ y => { y<number>(undefined); return y; } }${ 10 }`;
|
||||
tempTag1 `${ x => { x<number>(undefined); return x; } }${ (y: <T>(p: T) => T) => { y<number>(undefined); return y } }${ undefined }`;
|
||||
tempTag1 `${ (x: <T>(p: T) => T) => { x<number>(undefined); return x; } }${ y => { y<number>(undefined); return y; } }${ undefined }`;
|
||||
@ -25,6 +26,10 @@ function tempTag1(...rest) {
|
||||
// Otherwise, the arrow functions' parameters will be typed as 'any',
|
||||
// and it is an error to invoke an any-typed value with type arguments,
|
||||
// so this test will error.
|
||||
tempTag1 `${function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
}}${10}`;
|
||||
tempTag1 `${function (x) {
|
||||
x(undefined);
|
||||
return x;
|
||||
|
||||
@ -47,6 +47,15 @@ function tempTag1<T>(...rest: any[]): T {
|
||||
// Otherwise, the arrow functions' parameters will be typed as 'any',
|
||||
// and it is an error to invoke an any-typed value with type arguments,
|
||||
// so this test will error.
|
||||
tempTag1 `${ x => { x<number>(undefined); return x; } }${ 10 }`;
|
||||
>tempTag1 : { <T>(templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, x: T): T; <T>(templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, h: (x: <T>(p: T) => T) => <T>(p: T) => T, x: T): T; }
|
||||
>x => { x<number>(undefined); return x; } : (x: <T>(p: T) => T) => <T>(p: T) => T
|
||||
>x : <T>(p: T) => T
|
||||
>x<number>(undefined) : number
|
||||
>x : <T>(p: T) => T
|
||||
>undefined : undefined
|
||||
>x : <T>(p: T) => T
|
||||
|
||||
tempTag1 `${ x => { x<number>(undefined); return x; } }${ y => { y<number>(undefined); return y; } }${ 10 }`;
|
||||
>tempTag1 : { <T>(templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, x: T): T; <T>(templateStrs: TemplateStringsArray, f: (x: <T>(p: T) => T) => <T>(p: T) => T, h: (x: <T>(p: T) => T) => <T>(p: T) => T, x: T): T; }
|
||||
>x => { x<number>(undefined); return x; } : (x: <T>(p: T) => T) => <T>(p: T) => T
|
||||
|
||||
@ -0,0 +1,29 @@
|
||||
|
||||
function fun<T>(g: (x: T) => T, x: T): T;
|
||||
function fun<T>(g: (x: T) => T, h: (y: T) => T, x: T): T;
|
||||
function fun<T>(g: (x: T) => T, x: T): T {
|
||||
return g(x);
|
||||
}
|
||||
|
||||
var a = fun(x => x, 10);
|
||||
var b = fun((x => x), 10);
|
||||
var c = fun(((x => x)), 10);
|
||||
var d = fun((((x => x))), 10);
|
||||
|
||||
var e = fun(x => x, x => x, 10);
|
||||
var f = fun((x => x), (x => x), 10);
|
||||
var g = fun(((x => x)), ((x => x)), 10);
|
||||
var h = fun((((x => x))), ((x => x)), 10);
|
||||
|
||||
// Ternaries in parens
|
||||
var i = fun((Math.random() < 0.5 ? x => x : x => undefined), 10);
|
||||
var j = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10);
|
||||
var k = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10);
|
||||
var l = fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10);
|
||||
|
||||
var lambda1: (x: number) => number = x => x;
|
||||
var lambda2: (x: number) => number = (x => x);
|
||||
|
||||
type ObjType = { x: (p: number) => string; y: (p: string) => number };
|
||||
var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) };
|
||||
var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) });
|
||||
@ -0,0 +1,35 @@
|
||||
// These tests ensure that in cases where it may *appear* that a value has a type,
|
||||
// they actually are properly being contextually typed. The way we test this is
|
||||
// that we invoke contextually typed arguments with type arguments.
|
||||
// Since 'any' cannot be invoked with type arguments, we should get errors back.
|
||||
|
||||
type FuncType = (x: <T>(p: T) => T) => typeof x;
|
||||
|
||||
function fun<T>(f: FuncType, x: T): T;
|
||||
function fun<T>(f: FuncType, g: FuncType, x: T): T;
|
||||
function fun<T>(...rest: any[]): T {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
var a = fun(x => { x<number>(undefined); return x; }, 10);
|
||||
var b = fun((x => { x<number>(undefined); return x; }), 10);
|
||||
var c = fun(((x => { x<number>(undefined); return x; })), 10);
|
||||
var d = fun((((x => { x<number>(undefined); return x; }))), 10);
|
||||
|
||||
var e = fun(x => { x<number>(undefined); return x; }, x => { x<number>(undefined); return x; }, 10);
|
||||
var f = fun((x => { x<number>(undefined); return x; }),(x => { x<number>(undefined); return x; }), 10);
|
||||
var g = fun(((x => { x<number>(undefined); return x; })),((x => { x<number>(undefined); return x; })), 10);
|
||||
var h = fun((((x => { x<number>(undefined); return x; }))),((x => { x<number>(undefined); return x; })), 10);
|
||||
|
||||
// Ternaries in parens
|
||||
var i = fun((Math.random() < 0.5 ? x => { x<number>(undefined); return x; } : x => undefined), 10);
|
||||
var j = fun((Math.random() < 0.5 ? (x => { x<number>(undefined); return x; }) : (x => undefined)), 10);
|
||||
var k = fun((Math.random() < 0.5 ? (x => { x<number>(undefined); return x; }) : (x => undefined)), x => { x<number>(undefined); return x; }, 10);
|
||||
var l = fun(((Math.random() < 0.5 ? ((x => { x<number>(undefined); return x; })) : ((x => undefined)))),((x => { x<number>(undefined); return x; })), 10);
|
||||
|
||||
var lambda1: (x: number) => number = x => { x<number>(undefined); return x; };
|
||||
var lambda2: (x: number) => number = (x => { x<number>(undefined); return x; });
|
||||
|
||||
type ObjType = { x: (p: number) => string; y: (p: string) => number };
|
||||
var obj1: ObjType = { x: x => (x, undefined), y: y => (y, undefined) };
|
||||
var obj2: ObjType = ({ x: x => (x, undefined), y: y => (y, undefined) });
|
||||
@ -0,0 +1,21 @@
|
||||
// @target: ES6
|
||||
|
||||
// Contextual typing for parenthesized substitution expressions in tagged templates.
|
||||
|
||||
/**
|
||||
* tempFun - Can't have fun for too long.
|
||||
*/
|
||||
function tempFun<T>(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T;
|
||||
function tempFun<T>(tempStrs: TemplateStringsArray, g: (x: T) => T, h: (y: T) => T, x: T): T;
|
||||
function tempFun<T>(tempStrs: TemplateStringsArray, g: (x: T) => T, x: T): T {
|
||||
return g(x);
|
||||
}
|
||||
|
||||
var a = tempFun `${ x => x } ${ 10 }`
|
||||
var b = tempFun `${ (x => x) } ${ 10 }`
|
||||
var c = tempFun `${ ((x => x)) } ${ 10 }`
|
||||
var d = tempFun `${ x => x } ${ x => x } ${ 10 }`
|
||||
var e = tempFun `${ x => x } ${ (x => x) } ${ 10 }`
|
||||
var f = tempFun `${ x => x } ${ ((x => x)) } ${ 10 }`
|
||||
var g = tempFun `${ (x => x) } ${ (((x => x))) } ${ 10 }`
|
||||
var h = tempFun `${ (x => x) } ${ (((x => x))) } ${ undefined }`
|
||||
@ -12,6 +12,7 @@ function tempTag1<T>(...rest: any[]): T {
|
||||
// Otherwise, the arrow functions' parameters will be typed as 'any',
|
||||
// and it is an error to invoke an any-typed value with type arguments,
|
||||
// so this test will error.
|
||||
tempTag1 `${ x => { x<number>(undefined); return x; } }${ 10 }`;
|
||||
tempTag1 `${ x => { x<number>(undefined); return x; } }${ y => { y<number>(undefined); return y; } }${ 10 }`;
|
||||
tempTag1 `${ x => { x<number>(undefined); return x; } }${ (y: <T>(p: T) => T) => { y<number>(undefined); return y } }${ undefined }`;
|
||||
tempTag1 `${ (x: <T>(p: T) => T) => { x<number>(undefined); return x; } }${ y => { y<number>(undefined); return y; } }${ undefined }`;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user