From a689b9df38a3fd2d024b23db4eb8f48e83a17a97 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 14 Apr 2015 10:26:47 -0700 Subject: [PATCH 1/7] Conformance test for update incontextual type in function expression --- .../functionExpressionContextualTyping.js | 76 ++++++++ .../functionExpressionContextualTyping.types | 167 ++++++++++++++++++ ...tionExpressionContextualTyping1.errors.txt | 36 ++++ .../functionExpressionContextualTyping1.js | 36 ++++ .../functionExpressionContextualTyping.ts | 32 ++++ .../functionExpressionContextualTyping1.ts | 14 ++ 6 files changed, 361 insertions(+) create mode 100644 tests/baselines/reference/functionExpressionContextualTyping.js create mode 100644 tests/baselines/reference/functionExpressionContextualTyping.types create mode 100644 tests/baselines/reference/functionExpressionContextualTyping1.errors.txt create mode 100644 tests/baselines/reference/functionExpressionContextualTyping1.js create mode 100644 tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts create mode 100644 tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts diff --git a/tests/baselines/reference/functionExpressionContextualTyping.js b/tests/baselines/reference/functionExpressionContextualTyping.js new file mode 100644 index 0000000000000..a0ca1a928cefa --- /dev/null +++ b/tests/baselines/reference/functionExpressionContextualTyping.js @@ -0,0 +1,76 @@ +//// [functionExpressionContextualTyping.ts] +enum E { red, blue } + +var g0: (n: number, s:string) => number; +var g: ((s: string, w: boolean) => void) | ((n: number) => number); +var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); + +g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. +g = (k, h=true) => { k.toLowerCase() }; +g = (k) => { k.toLowerCase() }; +g = (i) => { + i.toExponential(); + return i; +}; // Per spec, no contextual signature can be extracted in this case. + +var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +h = (k, h) => { }; + +var i: typeof g0 | ((n: number, s: string) => string); +i = (foo, bar) => { return foo + 1; } +i = (foo, bar) => { return "hello"; } +var j: (name: string, num: number, boo: boolean) => void; +j = (name, number) => { }; + +var k: (n: E) => string = (number = 1) => { return "hello"; }; +var k1: (n: {}) => string = (number = 1) => { return "hello"; }; +class C { + constructor() { + var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { + return [j, k]; + } // Per spec, no contextual signature can be extracted in this case. + } +} + +//// [functionExpressionContextualTyping.js] +var E; +(function (E) { + E[E["red"] = 0] = "red"; + E[E["blue"] = 1] = "blue"; +})(E || (E = {})); +var g0; +var g; +var g1; +g1 = function (j, m) { }; // Per spec, no contextual signature can be extracted in this case. +g = function (k, h) { + if (h === void 0) { h = true; } + k.toLowerCase(); +}; +g = function (k) { k.toLowerCase(); }; +g = function (i) { + i.toExponential(); + return i; +}; // Per spec, no contextual signature can be extracted in this case. +var h; +h = function (k, h) { }; +var i; +i = function (foo, bar) { return foo + 1; }; +i = function (foo, bar) { return "hello"; }; +var j; +j = function (name, number) { }; +var k = function (number) { + if (number === void 0) { number = 1; } + return "hello"; +}; +var k1 = function (number) { + if (number === void 0) { number = 1; } + return "hello"; +}; +var C = (function () { + function C() { + var k = function (j, k) { + return [j, k]; + }; // Per spec, no contextual signature can be extracted in this case. + } + return C; +})(); diff --git a/tests/baselines/reference/functionExpressionContextualTyping.types b/tests/baselines/reference/functionExpressionContextualTyping.types new file mode 100644 index 0000000000000..f6ef4c836ec30 --- /dev/null +++ b/tests/baselines/reference/functionExpressionContextualTyping.types @@ -0,0 +1,167 @@ +=== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts === +enum E { red, blue } +>E : E, Symbol(E, Decl(functionExpressionContextualTyping.ts, 0, 0)) +>red : E, Symbol(E.red, Decl(functionExpressionContextualTyping.ts, 0, 8)) +>blue : E, Symbol(E.blue, Decl(functionExpressionContextualTyping.ts, 0, 13)) + +var g0: (n: number, s:string) => number; +>g0 : (n: number, s: string) => number, Symbol(g0, Decl(functionExpressionContextualTyping.ts, 2, 3)) +>n : number, Symbol(n, Decl(functionExpressionContextualTyping.ts, 2, 9)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 2, 19)) + +var g: ((s: string, w: boolean) => void) | ((n: number) => number); +>g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 3, 9)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 3, 19)) +>n : number, Symbol(n, Decl(functionExpressionContextualTyping.ts, 3, 45)) + +var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); +>g1 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(g1, Decl(functionExpressionContextualTyping.ts, 4, 3)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 4, 10)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 4, 20)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 4, 46)) +>w : number, Symbol(w, Decl(functionExpressionContextualTyping.ts, 4, 56)) + +g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. +>g1 = (j, m) => { } : (j: any, m: any) => void +>g1 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(g1, Decl(functionExpressionContextualTyping.ts, 4, 3)) +>(j, m) => { } : (j: any, m: any) => void +>j : any, Symbol(j, Decl(functionExpressionContextualTyping.ts, 6, 6)) +>m : any, Symbol(m, Decl(functionExpressionContextualTyping.ts, 6, 8)) + +g = (k, h=true) => { k.toLowerCase() }; +>g = (k, h=true) => { k.toLowerCase() } : (k: any, h?: boolean) => void +>g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) +>(k, h=true) => { k.toLowerCase() } : (k: any, h?: boolean) => void +>k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 7, 5)) +>h : boolean, Symbol(h, Decl(functionExpressionContextualTyping.ts, 7, 7)) +>true : boolean +>k.toLowerCase() : any +>k.toLowerCase : any +>k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 7, 5)) +>toLowerCase : any + +g = (k) => { k.toLowerCase() }; +>g = (k) => { k.toLowerCase() } : (k: any) => void +>g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) +>(k) => { k.toLowerCase() } : (k: any) => void +>k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 8, 5)) +>k.toLowerCase() : any +>k.toLowerCase : any +>k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 8, 5)) +>toLowerCase : any + +g = (i) => { +>g = (i) => { i.toExponential(); return i;} : (i: any) => any +>g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) +>(i) => { i.toExponential(); return i;} : (i: any) => any +>i : any, Symbol(i, Decl(functionExpressionContextualTyping.ts, 9, 5)) + + i.toExponential(); +>i.toExponential() : any +>i.toExponential : any +>i : any, Symbol(i, Decl(functionExpressionContextualTyping.ts, 9, 5)) +>toExponential : any + + return i; +>i : any, Symbol(i, Decl(functionExpressionContextualTyping.ts, 9, 5)) + +}; // Per spec, no contextual signature can be extracted in this case. + +var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +>h : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(h, Decl(functionExpressionContextualTyping.ts, 14, 3)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 14, 9)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 14, 19)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 14, 45)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 14, 55)) + +h = (k, h) => { }; +>h = (k, h) => { } : (k: string, h: boolean) => void +>h : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(h, Decl(functionExpressionContextualTyping.ts, 14, 3)) +>(k, h) => { } : (k: string, h: boolean) => void +>k : string, Symbol(k, Decl(functionExpressionContextualTyping.ts, 15, 5)) +>h : boolean, Symbol(h, Decl(functionExpressionContextualTyping.ts, 15, 7)) + +var i: typeof g0 | ((n: number, s: string) => string); +>i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping.ts, 17, 3)) +>g0 : (n: number, s: string) => number, Symbol(g0, Decl(functionExpressionContextualTyping.ts, 2, 3)) +>n : number, Symbol(n, Decl(functionExpressionContextualTyping.ts, 17, 21)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 17, 31)) + +i = (foo, bar) => { return foo + 1; } +>i = (foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number +>i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping.ts, 17, 3)) +>(foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number +>foo : number, Symbol(foo, Decl(functionExpressionContextualTyping.ts, 18, 5)) +>bar : string, Symbol(bar, Decl(functionExpressionContextualTyping.ts, 18, 9)) +>foo + 1 : number +>foo : number, Symbol(foo, Decl(functionExpressionContextualTyping.ts, 18, 5)) +>1 : number + +i = (foo, bar) => { return "hello"; } +>i = (foo, bar) => { return "hello"; } : (foo: number, bar: string) => string +>i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping.ts, 17, 3)) +>(foo, bar) => { return "hello"; } : (foo: number, bar: string) => string +>foo : number, Symbol(foo, Decl(functionExpressionContextualTyping.ts, 19, 5)) +>bar : string, Symbol(bar, Decl(functionExpressionContextualTyping.ts, 19, 9)) +>"hello" : string + +var j: (name: string, num: number, boo: boolean) => void; +>j : (name: string, num: number, boo: boolean) => void, Symbol(j, Decl(functionExpressionContextualTyping.ts, 20, 3)) +>name : string, Symbol(name, Decl(functionExpressionContextualTyping.ts, 20, 8)) +>num : number, Symbol(num, Decl(functionExpressionContextualTyping.ts, 20, 21)) +>boo : boolean, Symbol(boo, Decl(functionExpressionContextualTyping.ts, 20, 34)) + +j = (name, number) => { }; +>j = (name, number) => { } : (name: string, number: number) => void +>j : (name: string, num: number, boo: boolean) => void, Symbol(j, Decl(functionExpressionContextualTyping.ts, 20, 3)) +>(name, number) => { } : (name: string, number: number) => void +>name : string, Symbol(name, Decl(functionExpressionContextualTyping.ts, 21, 5)) +>number : number, Symbol(number, Decl(functionExpressionContextualTyping.ts, 21, 10)) + +var k: (n: E) => string = (number = 1) => { return "hello"; }; +>k : (n: E) => string, Symbol(k, Decl(functionExpressionContextualTyping.ts, 23, 3)) +>n : E, Symbol(n, Decl(functionExpressionContextualTyping.ts, 23, 8)) +>E : E, Symbol(E, Decl(functionExpressionContextualTyping.ts, 0, 0)) +>(number = 1) => { return "hello"; } : (number?: E) => string +>number : E, Symbol(number, Decl(functionExpressionContextualTyping.ts, 23, 27)) +>1 : number +>"hello" : string + +var k1: (n: {}) => string = (number = 1) => { return "hello"; }; +>k1 : (n: {}) => string, Symbol(k1, Decl(functionExpressionContextualTyping.ts, 24, 3)) +>n : {}, Symbol(n, Decl(functionExpressionContextualTyping.ts, 24, 9)) +>(number = 1) => { return "hello"; } : (number?: {}) => string +>number : {}, Symbol(number, Decl(functionExpressionContextualTyping.ts, 24, 29)) +>1 : number +>"hello" : string + +class C { +>C : C, Symbol(C, Decl(functionExpressionContextualTyping.ts, 24, 64)) +>T : T, Symbol(T, Decl(functionExpressionContextualTyping.ts, 25, 8)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) + + constructor() { + var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { +>k : ((j: T, k: U) => (T | U)[]) | ((j: number, k: U) => number[]), Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 11)) +>j : T, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 17)) +>T : T, Symbol(T, Decl(functionExpressionContextualTyping.ts, 25, 8)) +>k : U, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 22)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) +>T : T, Symbol(T, Decl(functionExpressionContextualTyping.ts, 25, 8)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) +>j : number, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 45)) +>k : U, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 55)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) +>(j, k) => { return [j, k]; } : (j: any, k: any) => any[] +>j : any, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 77)) +>k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 79)) + + return [j, k]; +>[j, k] : any[] +>j : any, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 77)) +>k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 79)) + + } // Per spec, no contextual signature can be extracted in this case. + } +} diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.errors.txt b/tests/baselines/reference/functionExpressionContextualTyping1.errors.txt new file mode 100644 index 0000000000000..fa69806ca3a71 --- /dev/null +++ b/tests/baselines/reference/functionExpressionContextualTyping1.errors.txt @@ -0,0 +1,36 @@ +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(3,1): error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. + Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. + Type 'boolean' is not assignable to type 'string'. +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(5,7): error TS2300: Duplicate identifier 'C'. +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(8,7): error TS2300: Duplicate identifier 'C'. +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(10,43): error TS2322: Type 'number' is not assignable to type 'T'. +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(10,50): error TS2322: Type 'number' is not assignable to type 'U'. + + +==== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts (5 errors) ==== + var g0: (n: number, s: string) => number + var i: typeof g0 | ((n: number, s: string) => string); + i = (foo, bar) => { return true; } + ~ +!!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. +!!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. +!!! error TS2322: Type 'boolean' is not assignable to type 'string'. + + class C { } + ~ +!!! error TS2300: Duplicate identifier 'C'. + + var j: (c: C) => number = (j) => { return 1; } + class C { + ~ +!!! error TS2300: Duplicate identifier 'C'. + constructor() { + var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { + ~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'T'. + ~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'U'. + return [j, k]; + } + } + } \ No newline at end of file diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.js b/tests/baselines/reference/functionExpressionContextualTyping1.js new file mode 100644 index 0000000000000..f0331c840703c --- /dev/null +++ b/tests/baselines/reference/functionExpressionContextualTyping1.js @@ -0,0 +1,36 @@ +//// [functionExpressionContextualTyping1.ts] +var g0: (n: number, s: string) => number +var i: typeof g0 | ((n: number, s: string) => string); +i = (foo, bar) => { return true; } + +class C { } + +var j: (c: C) => number = (j) => { return 1; } +class C { + constructor() { + var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { + return [j, k]; + } + } +} + +//// [functionExpressionContextualTyping1.js] +var g0; +var i; +i = function (foo, bar) { return true; }; +var C = (function () { + function C() { + } + return C; +})(); +var j = function (j) { return 1; }; +var C = (function () { + function C() { + var k = function (j, k) { + if (j === void 0) { j = 1; } + if (k === void 0) { k = 0; } + return [j, k]; + }; + } + return C; +})(); diff --git a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts new file mode 100644 index 0000000000000..1ede1c3fa7285 --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts @@ -0,0 +1,32 @@ +enum E { red, blue } + +var g0: (n: number, s:string) => number; +var g: ((s: string, w: boolean) => void) | ((n: number) => number); +var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); + +g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. +g = (k, h=true) => { k.toLowerCase() }; +g = (k) => { k.toLowerCase() }; +g = (i) => { + i.toExponential(); + return i; +}; // Per spec, no contextual signature can be extracted in this case. + +var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +h = (k, h) => { }; + +var i: typeof g0 | ((n: number, s: string) => string); +i = (foo, bar) => { return foo + 1; } +i = (foo, bar) => { return "hello"; } +var j: (name: string, num: number, boo: boolean) => void; +j = (name, number) => { }; + +var k: (n: E) => string = (number = 1) => { return "hello"; }; +var k1: (n: {}) => string = (number = 1) => { return "hello"; }; +class C { + constructor() { + var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { + return [j, k]; + } // Per spec, no contextual signature can be extracted in this case. + } +} \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts new file mode 100644 index 0000000000000..d22fff7e1387b --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts @@ -0,0 +1,14 @@ +var g0: (n: number, s: string) => number +var i: typeof g0 | ((n: number, s: string) => string); +i = (foo, bar) => { return true; } + +class C { } + +var j: (c: C) => number = (j) => { return 1; } +class C { + constructor() { + var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { + return [j, k]; + } + } +} \ No newline at end of file From 85af749239f1c73e1f8d934bba7f9bdaafe7809e Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 14 Apr 2015 12:55:54 -0700 Subject: [PATCH 2/7] Change file name to be more consistent --- .../functionExpressionContextualTyping.js | 76 -------- .../functionExpressionContextualTyping.types | 167 ------------------ ...tionExpressionContextualTyping1.errors.txt | 36 ---- .../functionExpressionContextualTyping.ts | 32 ---- .../functionExpressionContextualTyping1.ts | 32 +++- 5 files changed, 25 insertions(+), 318 deletions(-) delete mode 100644 tests/baselines/reference/functionExpressionContextualTyping.js delete mode 100644 tests/baselines/reference/functionExpressionContextualTyping.types delete mode 100644 tests/baselines/reference/functionExpressionContextualTyping1.errors.txt delete mode 100644 tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts diff --git a/tests/baselines/reference/functionExpressionContextualTyping.js b/tests/baselines/reference/functionExpressionContextualTyping.js deleted file mode 100644 index a0ca1a928cefa..0000000000000 --- a/tests/baselines/reference/functionExpressionContextualTyping.js +++ /dev/null @@ -1,76 +0,0 @@ -//// [functionExpressionContextualTyping.ts] -enum E { red, blue } - -var g0: (n: number, s:string) => number; -var g: ((s: string, w: boolean) => void) | ((n: number) => number); -var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); - -g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. -g = (k, h=true) => { k.toLowerCase() }; -g = (k) => { k.toLowerCase() }; -g = (i) => { - i.toExponential(); - return i; -}; // Per spec, no contextual signature can be extracted in this case. - -var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); -h = (k, h) => { }; - -var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return foo + 1; } -i = (foo, bar) => { return "hello"; } -var j: (name: string, num: number, boo: boolean) => void; -j = (name, number) => { }; - -var k: (n: E) => string = (number = 1) => { return "hello"; }; -var k1: (n: {}) => string = (number = 1) => { return "hello"; }; -class C { - constructor() { - var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { - return [j, k]; - } // Per spec, no contextual signature can be extracted in this case. - } -} - -//// [functionExpressionContextualTyping.js] -var E; -(function (E) { - E[E["red"] = 0] = "red"; - E[E["blue"] = 1] = "blue"; -})(E || (E = {})); -var g0; -var g; -var g1; -g1 = function (j, m) { }; // Per spec, no contextual signature can be extracted in this case. -g = function (k, h) { - if (h === void 0) { h = true; } - k.toLowerCase(); -}; -g = function (k) { k.toLowerCase(); }; -g = function (i) { - i.toExponential(); - return i; -}; // Per spec, no contextual signature can be extracted in this case. -var h; -h = function (k, h) { }; -var i; -i = function (foo, bar) { return foo + 1; }; -i = function (foo, bar) { return "hello"; }; -var j; -j = function (name, number) { }; -var k = function (number) { - if (number === void 0) { number = 1; } - return "hello"; -}; -var k1 = function (number) { - if (number === void 0) { number = 1; } - return "hello"; -}; -var C = (function () { - function C() { - var k = function (j, k) { - return [j, k]; - }; // Per spec, no contextual signature can be extracted in this case. - } - return C; -})(); diff --git a/tests/baselines/reference/functionExpressionContextualTyping.types b/tests/baselines/reference/functionExpressionContextualTyping.types deleted file mode 100644 index f6ef4c836ec30..0000000000000 --- a/tests/baselines/reference/functionExpressionContextualTyping.types +++ /dev/null @@ -1,167 +0,0 @@ -=== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts === -enum E { red, blue } ->E : E, Symbol(E, Decl(functionExpressionContextualTyping.ts, 0, 0)) ->red : E, Symbol(E.red, Decl(functionExpressionContextualTyping.ts, 0, 8)) ->blue : E, Symbol(E.blue, Decl(functionExpressionContextualTyping.ts, 0, 13)) - -var g0: (n: number, s:string) => number; ->g0 : (n: number, s: string) => number, Symbol(g0, Decl(functionExpressionContextualTyping.ts, 2, 3)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping.ts, 2, 9)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 2, 19)) - -var g: ((s: string, w: boolean) => void) | ((n: number) => number); ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 3, 9)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 3, 19)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping.ts, 3, 45)) - -var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); ->g1 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(g1, Decl(functionExpressionContextualTyping.ts, 4, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 4, 10)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 4, 20)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 4, 46)) ->w : number, Symbol(w, Decl(functionExpressionContextualTyping.ts, 4, 56)) - -g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. ->g1 = (j, m) => { } : (j: any, m: any) => void ->g1 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(g1, Decl(functionExpressionContextualTyping.ts, 4, 3)) ->(j, m) => { } : (j: any, m: any) => void ->j : any, Symbol(j, Decl(functionExpressionContextualTyping.ts, 6, 6)) ->m : any, Symbol(m, Decl(functionExpressionContextualTyping.ts, 6, 8)) - -g = (k, h=true) => { k.toLowerCase() }; ->g = (k, h=true) => { k.toLowerCase() } : (k: any, h?: boolean) => void ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) ->(k, h=true) => { k.toLowerCase() } : (k: any, h?: boolean) => void ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 7, 5)) ->h : boolean, Symbol(h, Decl(functionExpressionContextualTyping.ts, 7, 7)) ->true : boolean ->k.toLowerCase() : any ->k.toLowerCase : any ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 7, 5)) ->toLowerCase : any - -g = (k) => { k.toLowerCase() }; ->g = (k) => { k.toLowerCase() } : (k: any) => void ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) ->(k) => { k.toLowerCase() } : (k: any) => void ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 8, 5)) ->k.toLowerCase() : any ->k.toLowerCase : any ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 8, 5)) ->toLowerCase : any - -g = (i) => { ->g = (i) => { i.toExponential(); return i;} : (i: any) => any ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) ->(i) => { i.toExponential(); return i;} : (i: any) => any ->i : any, Symbol(i, Decl(functionExpressionContextualTyping.ts, 9, 5)) - - i.toExponential(); ->i.toExponential() : any ->i.toExponential : any ->i : any, Symbol(i, Decl(functionExpressionContextualTyping.ts, 9, 5)) ->toExponential : any - - return i; ->i : any, Symbol(i, Decl(functionExpressionContextualTyping.ts, 9, 5)) - -}; // Per spec, no contextual signature can be extracted in this case. - -var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); ->h : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(h, Decl(functionExpressionContextualTyping.ts, 14, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 14, 9)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 14, 19)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 14, 45)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 14, 55)) - -h = (k, h) => { }; ->h = (k, h) => { } : (k: string, h: boolean) => void ->h : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(h, Decl(functionExpressionContextualTyping.ts, 14, 3)) ->(k, h) => { } : (k: string, h: boolean) => void ->k : string, Symbol(k, Decl(functionExpressionContextualTyping.ts, 15, 5)) ->h : boolean, Symbol(h, Decl(functionExpressionContextualTyping.ts, 15, 7)) - -var i: typeof g0 | ((n: number, s: string) => string); ->i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping.ts, 17, 3)) ->g0 : (n: number, s: string) => number, Symbol(g0, Decl(functionExpressionContextualTyping.ts, 2, 3)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping.ts, 17, 21)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 17, 31)) - -i = (foo, bar) => { return foo + 1; } ->i = (foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number ->i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping.ts, 17, 3)) ->(foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping.ts, 18, 5)) ->bar : string, Symbol(bar, Decl(functionExpressionContextualTyping.ts, 18, 9)) ->foo + 1 : number ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping.ts, 18, 5)) ->1 : number - -i = (foo, bar) => { return "hello"; } ->i = (foo, bar) => { return "hello"; } : (foo: number, bar: string) => string ->i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping.ts, 17, 3)) ->(foo, bar) => { return "hello"; } : (foo: number, bar: string) => string ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping.ts, 19, 5)) ->bar : string, Symbol(bar, Decl(functionExpressionContextualTyping.ts, 19, 9)) ->"hello" : string - -var j: (name: string, num: number, boo: boolean) => void; ->j : (name: string, num: number, boo: boolean) => void, Symbol(j, Decl(functionExpressionContextualTyping.ts, 20, 3)) ->name : string, Symbol(name, Decl(functionExpressionContextualTyping.ts, 20, 8)) ->num : number, Symbol(num, Decl(functionExpressionContextualTyping.ts, 20, 21)) ->boo : boolean, Symbol(boo, Decl(functionExpressionContextualTyping.ts, 20, 34)) - -j = (name, number) => { }; ->j = (name, number) => { } : (name: string, number: number) => void ->j : (name: string, num: number, boo: boolean) => void, Symbol(j, Decl(functionExpressionContextualTyping.ts, 20, 3)) ->(name, number) => { } : (name: string, number: number) => void ->name : string, Symbol(name, Decl(functionExpressionContextualTyping.ts, 21, 5)) ->number : number, Symbol(number, Decl(functionExpressionContextualTyping.ts, 21, 10)) - -var k: (n: E) => string = (number = 1) => { return "hello"; }; ->k : (n: E) => string, Symbol(k, Decl(functionExpressionContextualTyping.ts, 23, 3)) ->n : E, Symbol(n, Decl(functionExpressionContextualTyping.ts, 23, 8)) ->E : E, Symbol(E, Decl(functionExpressionContextualTyping.ts, 0, 0)) ->(number = 1) => { return "hello"; } : (number?: E) => string ->number : E, Symbol(number, Decl(functionExpressionContextualTyping.ts, 23, 27)) ->1 : number ->"hello" : string - -var k1: (n: {}) => string = (number = 1) => { return "hello"; }; ->k1 : (n: {}) => string, Symbol(k1, Decl(functionExpressionContextualTyping.ts, 24, 3)) ->n : {}, Symbol(n, Decl(functionExpressionContextualTyping.ts, 24, 9)) ->(number = 1) => { return "hello"; } : (number?: {}) => string ->number : {}, Symbol(number, Decl(functionExpressionContextualTyping.ts, 24, 29)) ->1 : number ->"hello" : string - -class C { ->C : C, Symbol(C, Decl(functionExpressionContextualTyping.ts, 24, 64)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping.ts, 25, 8)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) - - constructor() { - var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { ->k : ((j: T, k: U) => (T | U)[]) | ((j: number, k: U) => number[]), Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 11)) ->j : T, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 17)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping.ts, 25, 8)) ->k : U, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 22)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping.ts, 25, 8)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) ->j : number, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 45)) ->k : U, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 55)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) ->(j, k) => { return [j, k]; } : (j: any, k: any) => any[] ->j : any, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 77)) ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 79)) - - return [j, k]; ->[j, k] : any[] ->j : any, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 77)) ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 79)) - - } // Per spec, no contextual signature can be extracted in this case. - } -} diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.errors.txt b/tests/baselines/reference/functionExpressionContextualTyping1.errors.txt deleted file mode 100644 index fa69806ca3a71..0000000000000 --- a/tests/baselines/reference/functionExpressionContextualTyping1.errors.txt +++ /dev/null @@ -1,36 +0,0 @@ -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(3,1): error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. - Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. - Type 'boolean' is not assignable to type 'string'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(5,7): error TS2300: Duplicate identifier 'C'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(8,7): error TS2300: Duplicate identifier 'C'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(10,43): error TS2322: Type 'number' is not assignable to type 'T'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(10,50): error TS2322: Type 'number' is not assignable to type 'U'. - - -==== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts (5 errors) ==== - var g0: (n: number, s: string) => number - var i: typeof g0 | ((n: number, s: string) => string); - i = (foo, bar) => { return true; } - ~ -!!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. -!!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. -!!! error TS2322: Type 'boolean' is not assignable to type 'string'. - - class C { } - ~ -!!! error TS2300: Duplicate identifier 'C'. - - var j: (c: C) => number = (j) => { return 1; } - class C { - ~ -!!! error TS2300: Duplicate identifier 'C'. - constructor() { - var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { - ~~~~~ -!!! error TS2322: Type 'number' is not assignable to type 'T'. - ~~~~~ -!!! error TS2322: Type 'number' is not assignable to type 'U'. - return [j, k]; - } - } - } \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts deleted file mode 100644 index 1ede1c3fa7285..0000000000000 --- a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts +++ /dev/null @@ -1,32 +0,0 @@ -enum E { red, blue } - -var g0: (n: number, s:string) => number; -var g: ((s: string, w: boolean) => void) | ((n: number) => number); -var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); - -g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. -g = (k, h=true) => { k.toLowerCase() }; -g = (k) => { k.toLowerCase() }; -g = (i) => { - i.toExponential(); - return i; -}; // Per spec, no contextual signature can be extracted in this case. - -var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); -h = (k, h) => { }; - -var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return foo + 1; } -i = (foo, bar) => { return "hello"; } -var j: (name: string, num: number, boo: boolean) => void; -j = (name, number) => { }; - -var k: (n: E) => string = (number = 1) => { return "hello"; }; -var k1: (n: {}) => string = (number = 1) => { return "hello"; }; -class C { - constructor() { - var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { - return [j, k]; - } // Per spec, no contextual signature can be extracted in this case. - } -} \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts index d22fff7e1387b..1ede1c3fa7285 100644 --- a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts +++ b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts @@ -1,14 +1,32 @@ -var g0: (n: number, s: string) => number -var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return true; } +enum E { red, blue } + +var g0: (n: number, s:string) => number; +var g: ((s: string, w: boolean) => void) | ((n: number) => number); +var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); + +g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. +g = (k, h=true) => { k.toLowerCase() }; +g = (k) => { k.toLowerCase() }; +g = (i) => { + i.toExponential(); + return i; +}; // Per spec, no contextual signature can be extracted in this case. -class C { } +var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +h = (k, h) => { }; + +var i: typeof g0 | ((n: number, s: string) => string); +i = (foo, bar) => { return foo + 1; } +i = (foo, bar) => { return "hello"; } +var j: (name: string, num: number, boo: boolean) => void; +j = (name, number) => { }; -var j: (c: C) => number = (j) => { return 1; } +var k: (n: E) => string = (number = 1) => { return "hello"; }; +var k1: (n: {}) => string = (number = 1) => { return "hello"; }; class C { constructor() { - var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { + var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { return [j, k]; - } + } // Per spec, no contextual signature can be extracted in this case. } } \ No newline at end of file From 496e23881b852c62d3ea564b470211ef220511fb Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 14 Apr 2015 12:55:54 -0700 Subject: [PATCH 3/7] Change file name to be more consistent --- .../functionExpressionContextualTyping.js | 76 -------- .../functionExpressionContextualTyping.types | 167 ------------------ ...tionExpressionContextualTyping1.errors.txt | 36 ---- .../functionExpressionContextualTyping.ts | 32 ---- .../functionExpressionContextualTyping1.ts | 32 +++- .../functionExpressionContextualTyping2.ts | 14 ++ 6 files changed, 39 insertions(+), 318 deletions(-) delete mode 100644 tests/baselines/reference/functionExpressionContextualTyping.js delete mode 100644 tests/baselines/reference/functionExpressionContextualTyping.types delete mode 100644 tests/baselines/reference/functionExpressionContextualTyping1.errors.txt delete mode 100644 tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts create mode 100644 tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts diff --git a/tests/baselines/reference/functionExpressionContextualTyping.js b/tests/baselines/reference/functionExpressionContextualTyping.js deleted file mode 100644 index a0ca1a928cefa..0000000000000 --- a/tests/baselines/reference/functionExpressionContextualTyping.js +++ /dev/null @@ -1,76 +0,0 @@ -//// [functionExpressionContextualTyping.ts] -enum E { red, blue } - -var g0: (n: number, s:string) => number; -var g: ((s: string, w: boolean) => void) | ((n: number) => number); -var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); - -g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. -g = (k, h=true) => { k.toLowerCase() }; -g = (k) => { k.toLowerCase() }; -g = (i) => { - i.toExponential(); - return i; -}; // Per spec, no contextual signature can be extracted in this case. - -var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); -h = (k, h) => { }; - -var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return foo + 1; } -i = (foo, bar) => { return "hello"; } -var j: (name: string, num: number, boo: boolean) => void; -j = (name, number) => { }; - -var k: (n: E) => string = (number = 1) => { return "hello"; }; -var k1: (n: {}) => string = (number = 1) => { return "hello"; }; -class C { - constructor() { - var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { - return [j, k]; - } // Per spec, no contextual signature can be extracted in this case. - } -} - -//// [functionExpressionContextualTyping.js] -var E; -(function (E) { - E[E["red"] = 0] = "red"; - E[E["blue"] = 1] = "blue"; -})(E || (E = {})); -var g0; -var g; -var g1; -g1 = function (j, m) { }; // Per spec, no contextual signature can be extracted in this case. -g = function (k, h) { - if (h === void 0) { h = true; } - k.toLowerCase(); -}; -g = function (k) { k.toLowerCase(); }; -g = function (i) { - i.toExponential(); - return i; -}; // Per spec, no contextual signature can be extracted in this case. -var h; -h = function (k, h) { }; -var i; -i = function (foo, bar) { return foo + 1; }; -i = function (foo, bar) { return "hello"; }; -var j; -j = function (name, number) { }; -var k = function (number) { - if (number === void 0) { number = 1; } - return "hello"; -}; -var k1 = function (number) { - if (number === void 0) { number = 1; } - return "hello"; -}; -var C = (function () { - function C() { - var k = function (j, k) { - return [j, k]; - }; // Per spec, no contextual signature can be extracted in this case. - } - return C; -})(); diff --git a/tests/baselines/reference/functionExpressionContextualTyping.types b/tests/baselines/reference/functionExpressionContextualTyping.types deleted file mode 100644 index f6ef4c836ec30..0000000000000 --- a/tests/baselines/reference/functionExpressionContextualTyping.types +++ /dev/null @@ -1,167 +0,0 @@ -=== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts === -enum E { red, blue } ->E : E, Symbol(E, Decl(functionExpressionContextualTyping.ts, 0, 0)) ->red : E, Symbol(E.red, Decl(functionExpressionContextualTyping.ts, 0, 8)) ->blue : E, Symbol(E.blue, Decl(functionExpressionContextualTyping.ts, 0, 13)) - -var g0: (n: number, s:string) => number; ->g0 : (n: number, s: string) => number, Symbol(g0, Decl(functionExpressionContextualTyping.ts, 2, 3)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping.ts, 2, 9)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 2, 19)) - -var g: ((s: string, w: boolean) => void) | ((n: number) => number); ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 3, 9)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 3, 19)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping.ts, 3, 45)) - -var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); ->g1 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(g1, Decl(functionExpressionContextualTyping.ts, 4, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 4, 10)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 4, 20)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 4, 46)) ->w : number, Symbol(w, Decl(functionExpressionContextualTyping.ts, 4, 56)) - -g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. ->g1 = (j, m) => { } : (j: any, m: any) => void ->g1 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(g1, Decl(functionExpressionContextualTyping.ts, 4, 3)) ->(j, m) => { } : (j: any, m: any) => void ->j : any, Symbol(j, Decl(functionExpressionContextualTyping.ts, 6, 6)) ->m : any, Symbol(m, Decl(functionExpressionContextualTyping.ts, 6, 8)) - -g = (k, h=true) => { k.toLowerCase() }; ->g = (k, h=true) => { k.toLowerCase() } : (k: any, h?: boolean) => void ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) ->(k, h=true) => { k.toLowerCase() } : (k: any, h?: boolean) => void ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 7, 5)) ->h : boolean, Symbol(h, Decl(functionExpressionContextualTyping.ts, 7, 7)) ->true : boolean ->k.toLowerCase() : any ->k.toLowerCase : any ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 7, 5)) ->toLowerCase : any - -g = (k) => { k.toLowerCase() }; ->g = (k) => { k.toLowerCase() } : (k: any) => void ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) ->(k) => { k.toLowerCase() } : (k: any) => void ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 8, 5)) ->k.toLowerCase() : any ->k.toLowerCase : any ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 8, 5)) ->toLowerCase : any - -g = (i) => { ->g = (i) => { i.toExponential(); return i;} : (i: any) => any ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping.ts, 3, 3)) ->(i) => { i.toExponential(); return i;} : (i: any) => any ->i : any, Symbol(i, Decl(functionExpressionContextualTyping.ts, 9, 5)) - - i.toExponential(); ->i.toExponential() : any ->i.toExponential : any ->i : any, Symbol(i, Decl(functionExpressionContextualTyping.ts, 9, 5)) ->toExponential : any - - return i; ->i : any, Symbol(i, Decl(functionExpressionContextualTyping.ts, 9, 5)) - -}; // Per spec, no contextual signature can be extracted in this case. - -var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); ->h : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(h, Decl(functionExpressionContextualTyping.ts, 14, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 14, 9)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 14, 19)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 14, 45)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping.ts, 14, 55)) - -h = (k, h) => { }; ->h = (k, h) => { } : (k: string, h: boolean) => void ->h : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(h, Decl(functionExpressionContextualTyping.ts, 14, 3)) ->(k, h) => { } : (k: string, h: boolean) => void ->k : string, Symbol(k, Decl(functionExpressionContextualTyping.ts, 15, 5)) ->h : boolean, Symbol(h, Decl(functionExpressionContextualTyping.ts, 15, 7)) - -var i: typeof g0 | ((n: number, s: string) => string); ->i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping.ts, 17, 3)) ->g0 : (n: number, s: string) => number, Symbol(g0, Decl(functionExpressionContextualTyping.ts, 2, 3)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping.ts, 17, 21)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping.ts, 17, 31)) - -i = (foo, bar) => { return foo + 1; } ->i = (foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number ->i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping.ts, 17, 3)) ->(foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping.ts, 18, 5)) ->bar : string, Symbol(bar, Decl(functionExpressionContextualTyping.ts, 18, 9)) ->foo + 1 : number ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping.ts, 18, 5)) ->1 : number - -i = (foo, bar) => { return "hello"; } ->i = (foo, bar) => { return "hello"; } : (foo: number, bar: string) => string ->i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping.ts, 17, 3)) ->(foo, bar) => { return "hello"; } : (foo: number, bar: string) => string ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping.ts, 19, 5)) ->bar : string, Symbol(bar, Decl(functionExpressionContextualTyping.ts, 19, 9)) ->"hello" : string - -var j: (name: string, num: number, boo: boolean) => void; ->j : (name: string, num: number, boo: boolean) => void, Symbol(j, Decl(functionExpressionContextualTyping.ts, 20, 3)) ->name : string, Symbol(name, Decl(functionExpressionContextualTyping.ts, 20, 8)) ->num : number, Symbol(num, Decl(functionExpressionContextualTyping.ts, 20, 21)) ->boo : boolean, Symbol(boo, Decl(functionExpressionContextualTyping.ts, 20, 34)) - -j = (name, number) => { }; ->j = (name, number) => { } : (name: string, number: number) => void ->j : (name: string, num: number, boo: boolean) => void, Symbol(j, Decl(functionExpressionContextualTyping.ts, 20, 3)) ->(name, number) => { } : (name: string, number: number) => void ->name : string, Symbol(name, Decl(functionExpressionContextualTyping.ts, 21, 5)) ->number : number, Symbol(number, Decl(functionExpressionContextualTyping.ts, 21, 10)) - -var k: (n: E) => string = (number = 1) => { return "hello"; }; ->k : (n: E) => string, Symbol(k, Decl(functionExpressionContextualTyping.ts, 23, 3)) ->n : E, Symbol(n, Decl(functionExpressionContextualTyping.ts, 23, 8)) ->E : E, Symbol(E, Decl(functionExpressionContextualTyping.ts, 0, 0)) ->(number = 1) => { return "hello"; } : (number?: E) => string ->number : E, Symbol(number, Decl(functionExpressionContextualTyping.ts, 23, 27)) ->1 : number ->"hello" : string - -var k1: (n: {}) => string = (number = 1) => { return "hello"; }; ->k1 : (n: {}) => string, Symbol(k1, Decl(functionExpressionContextualTyping.ts, 24, 3)) ->n : {}, Symbol(n, Decl(functionExpressionContextualTyping.ts, 24, 9)) ->(number = 1) => { return "hello"; } : (number?: {}) => string ->number : {}, Symbol(number, Decl(functionExpressionContextualTyping.ts, 24, 29)) ->1 : number ->"hello" : string - -class C { ->C : C, Symbol(C, Decl(functionExpressionContextualTyping.ts, 24, 64)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping.ts, 25, 8)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) - - constructor() { - var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { ->k : ((j: T, k: U) => (T | U)[]) | ((j: number, k: U) => number[]), Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 11)) ->j : T, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 17)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping.ts, 25, 8)) ->k : U, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 22)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping.ts, 25, 8)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) ->j : number, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 45)) ->k : U, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 55)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping.ts, 25, 10)) ->(j, k) => { return [j, k]; } : (j: any, k: any) => any[] ->j : any, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 77)) ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 79)) - - return [j, k]; ->[j, k] : any[] ->j : any, Symbol(j, Decl(functionExpressionContextualTyping.ts, 27, 77)) ->k : any, Symbol(k, Decl(functionExpressionContextualTyping.ts, 27, 79)) - - } // Per spec, no contextual signature can be extracted in this case. - } -} diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.errors.txt b/tests/baselines/reference/functionExpressionContextualTyping1.errors.txt deleted file mode 100644 index fa69806ca3a71..0000000000000 --- a/tests/baselines/reference/functionExpressionContextualTyping1.errors.txt +++ /dev/null @@ -1,36 +0,0 @@ -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(3,1): error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. - Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. - Type 'boolean' is not assignable to type 'string'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(5,7): error TS2300: Duplicate identifier 'C'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(8,7): error TS2300: Duplicate identifier 'C'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(10,43): error TS2322: Type 'number' is not assignable to type 'T'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts(10,50): error TS2322: Type 'number' is not assignable to type 'U'. - - -==== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts (5 errors) ==== - var g0: (n: number, s: string) => number - var i: typeof g0 | ((n: number, s: string) => string); - i = (foo, bar) => { return true; } - ~ -!!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. -!!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. -!!! error TS2322: Type 'boolean' is not assignable to type 'string'. - - class C { } - ~ -!!! error TS2300: Duplicate identifier 'C'. - - var j: (c: C) => number = (j) => { return 1; } - class C { - ~ -!!! error TS2300: Duplicate identifier 'C'. - constructor() { - var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { - ~~~~~ -!!! error TS2322: Type 'number' is not assignable to type 'T'. - ~~~~~ -!!! error TS2322: Type 'number' is not assignable to type 'U'. - return [j, k]; - } - } - } \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts deleted file mode 100644 index 1ede1c3fa7285..0000000000000 --- a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping.ts +++ /dev/null @@ -1,32 +0,0 @@ -enum E { red, blue } - -var g0: (n: number, s:string) => number; -var g: ((s: string, w: boolean) => void) | ((n: number) => number); -var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); - -g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. -g = (k, h=true) => { k.toLowerCase() }; -g = (k) => { k.toLowerCase() }; -g = (i) => { - i.toExponential(); - return i; -}; // Per spec, no contextual signature can be extracted in this case. - -var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); -h = (k, h) => { }; - -var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return foo + 1; } -i = (foo, bar) => { return "hello"; } -var j: (name: string, num: number, boo: boolean) => void; -j = (name, number) => { }; - -var k: (n: E) => string = (number = 1) => { return "hello"; }; -var k1: (n: {}) => string = (number = 1) => { return "hello"; }; -class C { - constructor() { - var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { - return [j, k]; - } // Per spec, no contextual signature can be extracted in this case. - } -} \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts index d22fff7e1387b..1ede1c3fa7285 100644 --- a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts +++ b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts @@ -1,14 +1,32 @@ -var g0: (n: number, s: string) => number -var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return true; } +enum E { red, blue } + +var g0: (n: number, s:string) => number; +var g: ((s: string, w: boolean) => void) | ((n: number) => number); +var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); + +g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. +g = (k, h=true) => { k.toLowerCase() }; +g = (k) => { k.toLowerCase() }; +g = (i) => { + i.toExponential(); + return i; +}; // Per spec, no contextual signature can be extracted in this case. -class C { } +var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +h = (k, h) => { }; + +var i: typeof g0 | ((n: number, s: string) => string); +i = (foo, bar) => { return foo + 1; } +i = (foo, bar) => { return "hello"; } +var j: (name: string, num: number, boo: boolean) => void; +j = (name, number) => { }; -var j: (c: C) => number = (j) => { return 1; } +var k: (n: E) => string = (number = 1) => { return "hello"; }; +var k1: (n: {}) => string = (number = 1) => { return "hello"; }; class C { constructor() { - var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { + var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { return [j, k]; - } + } // Per spec, no contextual signature can be extracted in this case. } } \ No newline at end of file diff --git a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts new file mode 100644 index 0000000000000..d22fff7e1387b --- /dev/null +++ b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts @@ -0,0 +1,14 @@ +var g0: (n: number, s: string) => number +var i: typeof g0 | ((n: number, s: string) => string); +i = (foo, bar) => { return true; } + +class C { } + +var j: (c: C) => number = (j) => { return 1; } +class C { + constructor() { + var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { + return [j, k]; + } + } +} \ No newline at end of file From 5ac12cfbc0c8464dfa8487a521afe4af9720fbe3 Mon Sep 17 00:00:00 2001 From: Yui T Date: Tue, 14 Apr 2015 13:05:29 -0700 Subject: [PATCH 4/7] Update test filenames --- .../functionExpressionContextualTyping1.js | 74 ++++++-- .../functionExpressionContextualTyping1.types | 167 ++++++++++++++++++ ...tionExpressionContextualTyping2.errors.txt | 36 ++++ .../functionExpressionContextualTyping2.js | 36 ++++ 4 files changed, 296 insertions(+), 17 deletions(-) create mode 100644 tests/baselines/reference/functionExpressionContextualTyping1.types create mode 100644 tests/baselines/reference/functionExpressionContextualTyping2.errors.txt create mode 100644 tests/baselines/reference/functionExpressionContextualTyping2.js diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.js b/tests/baselines/reference/functionExpressionContextualTyping1.js index f0331c840703c..6e528a5aedc88 100644 --- a/tests/baselines/reference/functionExpressionContextualTyping1.js +++ b/tests/baselines/reference/functionExpressionContextualTyping1.js @@ -1,36 +1,76 @@ //// [functionExpressionContextualTyping1.ts] -var g0: (n: number, s: string) => number -var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return true; } +enum E { red, blue } + +var g0: (n: number, s:string) => number; +var g: ((s: string, w: boolean) => void) | ((n: number) => number); +var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); + +g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. +g = (k, h=true) => { k.toLowerCase() }; +g = (k) => { k.toLowerCase() }; +g = (i) => { + i.toExponential(); + return i; +}; // Per spec, no contextual signature can be extracted in this case. -class C { } +var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +h = (k, h) => { }; + +var i: typeof g0 | ((n: number, s: string) => string); +i = (foo, bar) => { return foo + 1; } +i = (foo, bar) => { return "hello"; } +var j: (name: string, num: number, boo: boolean) => void; +j = (name, number) => { }; -var j: (c: C) => number = (j) => { return 1; } +var k: (n: E) => string = (number = 1) => { return "hello"; }; +var k1: (n: {}) => string = (number = 1) => { return "hello"; }; class C { constructor() { - var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { + var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { return [j, k]; - } + } // Per spec, no contextual signature can be extracted in this case. } } //// [functionExpressionContextualTyping1.js] +var E; +(function (E) { + E[E["red"] = 0] = "red"; + E[E["blue"] = 1] = "blue"; +})(E || (E = {})); var g0; +var g; +var g1; +g1 = function (j, m) { }; // Per spec, no contextual signature can be extracted in this case. +g = function (k, h) { + if (h === void 0) { h = true; } + k.toLowerCase(); +}; +g = function (k) { k.toLowerCase(); }; +g = function (i) { + i.toExponential(); + return i; +}; // Per spec, no contextual signature can be extracted in this case. +var h; +h = function (k, h) { }; var i; -i = function (foo, bar) { return true; }; -var C = (function () { - function C() { - } - return C; -})(); -var j = function (j) { return 1; }; +i = function (foo, bar) { return foo + 1; }; +i = function (foo, bar) { return "hello"; }; +var j; +j = function (name, number) { }; +var k = function (number) { + if (number === void 0) { number = 1; } + return "hello"; +}; +var k1 = function (number) { + if (number === void 0) { number = 1; } + return "hello"; +}; var C = (function () { function C() { var k = function (j, k) { - if (j === void 0) { j = 1; } - if (k === void 0) { k = 0; } return [j, k]; - }; + }; // Per spec, no contextual signature can be extracted in this case. } return C; })(); diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.types b/tests/baselines/reference/functionExpressionContextualTyping1.types new file mode 100644 index 0000000000000..3a1ce95bb9999 --- /dev/null +++ b/tests/baselines/reference/functionExpressionContextualTyping1.types @@ -0,0 +1,167 @@ +=== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts === +enum E { red, blue } +>E : E, Symbol(E, Decl(functionExpressionContextualTyping1.ts, 0, 0)) +>red : E, Symbol(E.red, Decl(functionExpressionContextualTyping1.ts, 0, 8)) +>blue : E, Symbol(E.blue, Decl(functionExpressionContextualTyping1.ts, 0, 13)) + +var g0: (n: number, s:string) => number; +>g0 : (n: number, s: string) => number, Symbol(g0, Decl(functionExpressionContextualTyping1.ts, 2, 3)) +>n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 2, 9)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 2, 19)) + +var g: ((s: string, w: boolean) => void) | ((n: number) => number); +>g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping1.ts, 3, 3)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 3, 9)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 3, 19)) +>n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 3, 45)) + +var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); +>g1 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(g1, Decl(functionExpressionContextualTyping1.ts, 4, 3)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 4, 10)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 4, 20)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 4, 46)) +>w : number, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 4, 56)) + +g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. +>g1 = (j, m) => { } : (j: any, m: any) => void +>g1 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(g1, Decl(functionExpressionContextualTyping1.ts, 4, 3)) +>(j, m) => { } : (j: any, m: any) => void +>j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 6, 6)) +>m : any, Symbol(m, Decl(functionExpressionContextualTyping1.ts, 6, 8)) + +g = (k, h=true) => { k.toLowerCase() }; +>g = (k, h=true) => { k.toLowerCase() } : (k: any, h?: boolean) => void +>g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping1.ts, 3, 3)) +>(k, h=true) => { k.toLowerCase() } : (k: any, h?: boolean) => void +>k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 7, 5)) +>h : boolean, Symbol(h, Decl(functionExpressionContextualTyping1.ts, 7, 7)) +>true : boolean +>k.toLowerCase() : any +>k.toLowerCase : any +>k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 7, 5)) +>toLowerCase : any + +g = (k) => { k.toLowerCase() }; +>g = (k) => { k.toLowerCase() } : (k: any) => void +>g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping1.ts, 3, 3)) +>(k) => { k.toLowerCase() } : (k: any) => void +>k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 8, 5)) +>k.toLowerCase() : any +>k.toLowerCase : any +>k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 8, 5)) +>toLowerCase : any + +g = (i) => { +>g = (i) => { i.toExponential(); return i;} : (i: any) => any +>g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping1.ts, 3, 3)) +>(i) => { i.toExponential(); return i;} : (i: any) => any +>i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 9, 5)) + + i.toExponential(); +>i.toExponential() : any +>i.toExponential : any +>i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 9, 5)) +>toExponential : any + + return i; +>i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 9, 5)) + +}; // Per spec, no contextual signature can be extracted in this case. + +var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +>h : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(h, Decl(functionExpressionContextualTyping1.ts, 14, 3)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 14, 9)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 14, 19)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 14, 45)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 14, 55)) + +h = (k, h) => { }; +>h = (k, h) => { } : (k: string, h: boolean) => void +>h : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(h, Decl(functionExpressionContextualTyping1.ts, 14, 3)) +>(k, h) => { } : (k: string, h: boolean) => void +>k : string, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 15, 5)) +>h : boolean, Symbol(h, Decl(functionExpressionContextualTyping1.ts, 15, 7)) + +var i: typeof g0 | ((n: number, s: string) => string); +>i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping1.ts, 17, 3)) +>g0 : (n: number, s: string) => number, Symbol(g0, Decl(functionExpressionContextualTyping1.ts, 2, 3)) +>n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 17, 21)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 17, 31)) + +i = (foo, bar) => { return foo + 1; } +>i = (foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number +>i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping1.ts, 17, 3)) +>(foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number +>foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 18, 5)) +>bar : string, Symbol(bar, Decl(functionExpressionContextualTyping1.ts, 18, 9)) +>foo + 1 : number +>foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 18, 5)) +>1 : number + +i = (foo, bar) => { return "hello"; } +>i = (foo, bar) => { return "hello"; } : (foo: number, bar: string) => string +>i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping1.ts, 17, 3)) +>(foo, bar) => { return "hello"; } : (foo: number, bar: string) => string +>foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 19, 5)) +>bar : string, Symbol(bar, Decl(functionExpressionContextualTyping1.ts, 19, 9)) +>"hello" : string + +var j: (name: string, num: number, boo: boolean) => void; +>j : (name: string, num: number, boo: boolean) => void, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 20, 3)) +>name : string, Symbol(name, Decl(functionExpressionContextualTyping1.ts, 20, 8)) +>num : number, Symbol(num, Decl(functionExpressionContextualTyping1.ts, 20, 21)) +>boo : boolean, Symbol(boo, Decl(functionExpressionContextualTyping1.ts, 20, 34)) + +j = (name, number) => { }; +>j = (name, number) => { } : (name: string, number: number) => void +>j : (name: string, num: number, boo: boolean) => void, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 20, 3)) +>(name, number) => { } : (name: string, number: number) => void +>name : string, Symbol(name, Decl(functionExpressionContextualTyping1.ts, 21, 5)) +>number : number, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 21, 10)) + +var k: (n: E) => string = (number = 1) => { return "hello"; }; +>k : (n: E) => string, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 23, 3)) +>n : E, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 23, 8)) +>E : E, Symbol(E, Decl(functionExpressionContextualTyping1.ts, 0, 0)) +>(number = 1) => { return "hello"; } : (number?: E) => string +>number : E, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 23, 27)) +>1 : number +>"hello" : string + +var k1: (n: {}) => string = (number = 1) => { return "hello"; }; +>k1 : (n: {}) => string, Symbol(k1, Decl(functionExpressionContextualTyping1.ts, 24, 3)) +>n : {}, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 24, 9)) +>(number = 1) => { return "hello"; } : (number?: {}) => string +>number : {}, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 24, 29)) +>1 : number +>"hello" : string + +class C { +>C : C, Symbol(C, Decl(functionExpressionContextualTyping1.ts, 24, 64)) +>T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 25, 8)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 25, 10)) + + constructor() { + var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { +>k : ((j: T, k: U) => (T | U)[]) | ((j: number, k: U) => number[]), Symbol(k, Decl(functionExpressionContextualTyping1.ts, 27, 11)) +>j : T, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 27, 17)) +>T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 25, 8)) +>k : U, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 27, 22)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 25, 10)) +>T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 25, 8)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 25, 10)) +>j : number, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 27, 45)) +>k : U, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 27, 55)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 25, 10)) +>(j, k) => { return [j, k]; } : (j: any, k: any) => any[] +>j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 27, 77)) +>k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 27, 79)) + + return [j, k]; +>[j, k] : any[] +>j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 27, 77)) +>k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 27, 79)) + + } // Per spec, no contextual signature can be extracted in this case. + } +} diff --git a/tests/baselines/reference/functionExpressionContextualTyping2.errors.txt b/tests/baselines/reference/functionExpressionContextualTyping2.errors.txt new file mode 100644 index 0000000000000..d9622c50e420d --- /dev/null +++ b/tests/baselines/reference/functionExpressionContextualTyping2.errors.txt @@ -0,0 +1,36 @@ +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(3,1): error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. + Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. + Type 'boolean' is not assignable to type 'string'. +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(5,7): error TS2300: Duplicate identifier 'C'. +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(8,7): error TS2300: Duplicate identifier 'C'. +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(10,43): error TS2322: Type 'number' is not assignable to type 'T'. +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(10,50): error TS2322: Type 'number' is not assignable to type 'U'. + + +==== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts (5 errors) ==== + var g0: (n: number, s: string) => number + var i: typeof g0 | ((n: number, s: string) => string); + i = (foo, bar) => { return true; } + ~ +!!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. +!!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. +!!! error TS2322: Type 'boolean' is not assignable to type 'string'. + + class C { } + ~ +!!! error TS2300: Duplicate identifier 'C'. + + var j: (c: C) => number = (j) => { return 1; } + class C { + ~ +!!! error TS2300: Duplicate identifier 'C'. + constructor() { + var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { + ~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'T'. + ~~~~~ +!!! error TS2322: Type 'number' is not assignable to type 'U'. + return [j, k]; + } + } + } \ No newline at end of file diff --git a/tests/baselines/reference/functionExpressionContextualTyping2.js b/tests/baselines/reference/functionExpressionContextualTyping2.js new file mode 100644 index 0000000000000..87d3e1ed9efaf --- /dev/null +++ b/tests/baselines/reference/functionExpressionContextualTyping2.js @@ -0,0 +1,36 @@ +//// [functionExpressionContextualTyping2.ts] +var g0: (n: number, s: string) => number +var i: typeof g0 | ((n: number, s: string) => string); +i = (foo, bar) => { return true; } + +class C { } + +var j: (c: C) => number = (j) => { return 1; } +class C { + constructor() { + var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { + return [j, k]; + } + } +} + +//// [functionExpressionContextualTyping2.js] +var g0; +var i; +i = function (foo, bar) { return true; }; +var C = (function () { + function C() { + } + return C; +})(); +var j = function (j) { return 1; }; +var C = (function () { + function C() { + var k = function (j, k) { + if (j === void 0) { j = 1; } + if (k === void 0) { k = 0; } + return [j, k]; + }; + } + return C; +})(); From 6d9c1f4c4ae7820b9c69caee21ba6bf6cb237ae4 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Apr 2015 15:39:12 -0700 Subject: [PATCH 5/7] Add spec description into tests --- .../functionExpressionContextualTyping1.js | 126 +++++--- .../functionExpressionContextualTyping1.types | 299 ++++++++++-------- ...tionExpressionContextualTyping2.errors.txt | 45 +-- .../functionExpressionContextualTyping2.js | 52 ++- .../functionExpressionContextualTyping1.ts | 64 ++-- .../functionExpressionContextualTyping2.ts | 23 +- 6 files changed, 343 insertions(+), 266 deletions(-) diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.js b/tests/baselines/reference/functionExpressionContextualTyping1.js index 6e528a5aedc88..8d60572b30f74 100644 --- a/tests/baselines/reference/functionExpressionContextualTyping1.js +++ b/tests/baselines/reference/functionExpressionContextualTyping1.js @@ -1,29 +1,53 @@ //// [functionExpressionContextualTyping1.ts] +// When a function expression with no type parameters and no parameter type annotations +// is contextually typed (section 4.19) by a type T and a contextual signature S can be extracted from T + enum E { red, blue } -var g0: (n: number, s:string) => number; -var g: ((s: string, w: boolean) => void) | ((n: number) => number); -var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); +// A contextual signature S is extracted from a function type T as follows: +// If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature. -g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. -g = (k, h=true) => { k.toLowerCase() }; -g = (k) => { k.toLowerCase() }; -g = (i) => { - i.toExponential(); - return i; -}; // Per spec, no contextual signature can be extracted in this case. +var a0: (n: number, s: string) => number = (num, str) => { + num.toExponential(); + return 0; +} + +class Class { + foo() { } +} -var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); -h = (k, h) => { }; +var a1: (c: Class) => number = (a1) => { + a1.foo(); + return 1; +} -var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return foo + 1; } -i = (foo, bar) => { return "hello"; } -var j: (name: string, num: number, boo: boolean) => void; -j = (name, number) => { }; +// A contextual signature S is extracted from a function type T as follows: +// If T is a union type, let U be the set of element types in T that have call signatures. +// If each type in U has exactly one call signature and that call signature is non- generic, +// and if all of the signatures are identical ignoring return types, +// then S is a signature with the same parameters and a union of the return types. +var b1: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +b1 = (k, h) => { }; +var b2: typeof a0 | ((n: number, s: string) => string); +b2 = (foo, bar) => { return foo + 1; } +b2 = (foo, bar) => { return "hello"; } +var b3: (name: string, num: number, boo: boolean) => void; +b3 = (name, number) => { }; + +var b4: (n: E) => string = (number = 1) => { return "hello"; }; +var b5: (n: {}) => string = (number = "string") => { return "hello"; }; + +// A contextual signature S is extracted from a function type T as follows: +// Otherwise, no contextual signature can be extracted from T and S is undefined. +var b6: ((s: string, w: boolean) => void) | ((n: number) => number); +var b7: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); +b6 = (k) => { k.toLowerCase() }; +b6 = (i) => { + i.toExponential(); + return i; +}; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) +b7 = (j, m) => { }; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) -var k: (n: E) => string = (number = 1) => { return "hello"; }; -var k1: (n: {}) => string = (number = 1) => { return "hello"; }; class C { constructor() { var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { @@ -33,39 +57,59 @@ class C { } //// [functionExpressionContextualTyping1.js] +// When a function expression with no type parameters and no parameter type annotations +// is contextually typed (section 4.19) by a type T and a contextual signature S can be extracted from T var E; (function (E) { E[E["red"] = 0] = "red"; E[E["blue"] = 1] = "blue"; })(E || (E = {})); -var g0; -var g; -var g1; -g1 = function (j, m) { }; // Per spec, no contextual signature can be extracted in this case. -g = function (k, h) { - if (h === void 0) { h = true; } - k.toLowerCase(); +// A contextual signature S is extracted from a function type T as follows: +// If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature. +var a0 = function (num, str) { + num.toExponential(); + return 0; }; -g = function (k) { k.toLowerCase(); }; -g = function (i) { - i.toExponential(); - return i; -}; // Per spec, no contextual signature can be extracted in this case. -var h; -h = function (k, h) { }; -var i; -i = function (foo, bar) { return foo + 1; }; -i = function (foo, bar) { return "hello"; }; -var j; -j = function (name, number) { }; -var k = function (number) { +var Class = (function () { + function Class() { + } + Class.prototype.foo = function () { }; + return Class; +})(); +var a1 = function (a1) { + a1.foo(); + return 1; +}; +// A contextual signature S is extracted from a function type T as follows: +// If T is a union type, let U be the set of element types in T that have call signatures. +// If each type in U has exactly one call signature and that call signature is non- generic, +// and if all of the signatures are identical ignoring return types, +// then S is a signature with the same parameters and a union of the return types. +var b1; +b1 = function (k, h) { }; +var b2; +b2 = function (foo, bar) { return foo + 1; }; +b2 = function (foo, bar) { return "hello"; }; +var b3; +b3 = function (name, number) { }; +var b4 = function (number) { if (number === void 0) { number = 1; } return "hello"; }; -var k1 = function (number) { - if (number === void 0) { number = 1; } +var b5 = function (number) { + if (number === void 0) { number = "string"; } return "hello"; }; +// A contextual signature S is extracted from a function type T as follows: +// Otherwise, no contextual signature can be extracted from T and S is undefined. +var b6; +var b7; +b6 = function (k) { k.toLowerCase(); }; +b6 = function (i) { + i.toExponential(); + return i; +}; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) +b7 = function (j, m) { }; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) var C = (function () { function C() { var k = function (j, k) { diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.types b/tests/baselines/reference/functionExpressionContextualTyping1.types index 3a1ce95bb9999..f7f04d5ed0fd2 100644 --- a/tests/baselines/reference/functionExpressionContextualTyping1.types +++ b/tests/baselines/reference/functionExpressionContextualTyping1.types @@ -1,166 +1,205 @@ === tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts === +// When a function expression with no type parameters and no parameter type annotations +// is contextually typed (section 4.19) by a type T and a contextual signature S can be extracted from T + enum E { red, blue } >E : E, Symbol(E, Decl(functionExpressionContextualTyping1.ts, 0, 0)) ->red : E, Symbol(E.red, Decl(functionExpressionContextualTyping1.ts, 0, 8)) ->blue : E, Symbol(E.blue, Decl(functionExpressionContextualTyping1.ts, 0, 13)) - -var g0: (n: number, s:string) => number; ->g0 : (n: number, s: string) => number, Symbol(g0, Decl(functionExpressionContextualTyping1.ts, 2, 3)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 2, 9)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 2, 19)) - -var g: ((s: string, w: boolean) => void) | ((n: number) => number); ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping1.ts, 3, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 3, 9)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 3, 19)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 3, 45)) - -var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); ->g1 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(g1, Decl(functionExpressionContextualTyping1.ts, 4, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 4, 10)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 4, 20)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 4, 46)) ->w : number, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 4, 56)) - -g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. ->g1 = (j, m) => { } : (j: any, m: any) => void ->g1 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(g1, Decl(functionExpressionContextualTyping1.ts, 4, 3)) ->(j, m) => { } : (j: any, m: any) => void ->j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 6, 6)) ->m : any, Symbol(m, Decl(functionExpressionContextualTyping1.ts, 6, 8)) - -g = (k, h=true) => { k.toLowerCase() }; ->g = (k, h=true) => { k.toLowerCase() } : (k: any, h?: boolean) => void ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping1.ts, 3, 3)) ->(k, h=true) => { k.toLowerCase() } : (k: any, h?: boolean) => void ->k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 7, 5)) ->h : boolean, Symbol(h, Decl(functionExpressionContextualTyping1.ts, 7, 7)) ->true : boolean ->k.toLowerCase() : any ->k.toLowerCase : any ->k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 7, 5)) ->toLowerCase : any - -g = (k) => { k.toLowerCase() }; ->g = (k) => { k.toLowerCase() } : (k: any) => void ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping1.ts, 3, 3)) ->(k) => { k.toLowerCase() } : (k: any) => void ->k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 8, 5)) ->k.toLowerCase() : any ->k.toLowerCase : any ->k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 8, 5)) ->toLowerCase : any - -g = (i) => { ->g = (i) => { i.toExponential(); return i;} : (i: any) => any ->g : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(g, Decl(functionExpressionContextualTyping1.ts, 3, 3)) ->(i) => { i.toExponential(); return i;} : (i: any) => any ->i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 9, 5)) - - i.toExponential(); ->i.toExponential() : any ->i.toExponential : any ->i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 9, 5)) ->toExponential : any +>red : E, Symbol(E.red, Decl(functionExpressionContextualTyping1.ts, 3, 8)) +>blue : E, Symbol(E.blue, Decl(functionExpressionContextualTyping1.ts, 3, 13)) + +// A contextual signature S is extracted from a function type T as follows: +// If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature. + +var a0: (n: number, s: string) => number = (num, str) => { +>a0 : (n: number, s: string) => number, Symbol(a0, Decl(functionExpressionContextualTyping1.ts, 8, 3)) +>n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 8, 9)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 8, 19)) +>(num, str) => { num.toExponential(); return 0;} : (num: number, str: string) => number +>num : number, Symbol(num, Decl(functionExpressionContextualTyping1.ts, 8, 44)) +>str : string, Symbol(str, Decl(functionExpressionContextualTyping1.ts, 8, 48)) + + num.toExponential(); +>num.toExponential() : string +>num.toExponential : (fractionDigits?: number) => string, Symbol(Number.toExponential, Decl(lib.d.ts, 469, 45)) +>num : number, Symbol(num, Decl(functionExpressionContextualTyping1.ts, 8, 44)) +>toExponential : (fractionDigits?: number) => string, Symbol(Number.toExponential, Decl(lib.d.ts, 469, 45)) + + return 0; +>0 : number +} - return i; ->i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 9, 5)) +class Class { +>Class : Class, Symbol(Class, Decl(functionExpressionContextualTyping1.ts, 11, 1)) +>T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 13, 12)) -}; // Per spec, no contextual signature can be extracted in this case. + foo() { } +>foo : () => void, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 13, 16)) +} -var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); ->h : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(h, Decl(functionExpressionContextualTyping1.ts, 14, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 14, 9)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 14, 19)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 14, 45)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 14, 55)) +var a1: (c: Class) => number = (a1) => { +>a1 : (c: Class) => number, Symbol(a1, Decl(functionExpressionContextualTyping1.ts, 17, 3)) +>c : Class, Symbol(c, Decl(functionExpressionContextualTyping1.ts, 17, 9)) +>Class : Class, Symbol(Class, Decl(functionExpressionContextualTyping1.ts, 11, 1)) +>Number : Number, Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) +>(a1) => { a1.foo(); return 1;} : (a1: Class) => number +>a1 : Class, Symbol(a1, Decl(functionExpressionContextualTyping1.ts, 17, 40)) + + a1.foo(); +>a1.foo() : void +>a1.foo : () => void, Symbol(Class.foo, Decl(functionExpressionContextualTyping1.ts, 13, 16)) +>a1 : Class, Symbol(a1, Decl(functionExpressionContextualTyping1.ts, 17, 40)) +>foo : () => void, Symbol(Class.foo, Decl(functionExpressionContextualTyping1.ts, 13, 16)) + + return 1; +>1 : number +} -h = (k, h) => { }; ->h = (k, h) => { } : (k: string, h: boolean) => void ->h : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(h, Decl(functionExpressionContextualTyping1.ts, 14, 3)) +// A contextual signature S is extracted from a function type T as follows: +// If T is a union type, let U be the set of element types in T that have call signatures. +// If each type in U has exactly one call signature and that call signature is non- generic, +// and if all of the signatures are identical ignoring return types, +// then S is a signature with the same parameters and a union of the return types. +var b1: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +>b1 : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(b1, Decl(functionExpressionContextualTyping1.ts, 27, 3)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 27, 10)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 27, 20)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 27, 46)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 27, 56)) + +b1 = (k, h) => { }; +>b1 = (k, h) => { } : (k: string, h: boolean) => void +>b1 : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(b1, Decl(functionExpressionContextualTyping1.ts, 27, 3)) >(k, h) => { } : (k: string, h: boolean) => void ->k : string, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 15, 5)) ->h : boolean, Symbol(h, Decl(functionExpressionContextualTyping1.ts, 15, 7)) - -var i: typeof g0 | ((n: number, s: string) => string); ->i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping1.ts, 17, 3)) ->g0 : (n: number, s: string) => number, Symbol(g0, Decl(functionExpressionContextualTyping1.ts, 2, 3)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 17, 21)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 17, 31)) - -i = (foo, bar) => { return foo + 1; } ->i = (foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number ->i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping1.ts, 17, 3)) +>k : string, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 28, 6)) +>h : boolean, Symbol(h, Decl(functionExpressionContextualTyping1.ts, 28, 8)) + +var b2: typeof a0 | ((n: number, s: string) => string); +>b2 : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(b2, Decl(functionExpressionContextualTyping1.ts, 29, 3)) +>a0 : (n: number, s: string) => number, Symbol(a0, Decl(functionExpressionContextualTyping1.ts, 8, 3)) +>n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 29, 22)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 29, 32)) + +b2 = (foo, bar) => { return foo + 1; } +>b2 = (foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number +>b2 : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(b2, Decl(functionExpressionContextualTyping1.ts, 29, 3)) >(foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 18, 5)) ->bar : string, Symbol(bar, Decl(functionExpressionContextualTyping1.ts, 18, 9)) +>foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 30, 6)) +>bar : string, Symbol(bar, Decl(functionExpressionContextualTyping1.ts, 30, 10)) >foo + 1 : number ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 18, 5)) +>foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 30, 6)) >1 : number -i = (foo, bar) => { return "hello"; } ->i = (foo, bar) => { return "hello"; } : (foo: number, bar: string) => string ->i : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(i, Decl(functionExpressionContextualTyping1.ts, 17, 3)) +b2 = (foo, bar) => { return "hello"; } +>b2 = (foo, bar) => { return "hello"; } : (foo: number, bar: string) => string +>b2 : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(b2, Decl(functionExpressionContextualTyping1.ts, 29, 3)) >(foo, bar) => { return "hello"; } : (foo: number, bar: string) => string ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 19, 5)) ->bar : string, Symbol(bar, Decl(functionExpressionContextualTyping1.ts, 19, 9)) +>foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 31, 6)) +>bar : string, Symbol(bar, Decl(functionExpressionContextualTyping1.ts, 31, 10)) >"hello" : string -var j: (name: string, num: number, boo: boolean) => void; ->j : (name: string, num: number, boo: boolean) => void, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 20, 3)) ->name : string, Symbol(name, Decl(functionExpressionContextualTyping1.ts, 20, 8)) ->num : number, Symbol(num, Decl(functionExpressionContextualTyping1.ts, 20, 21)) ->boo : boolean, Symbol(boo, Decl(functionExpressionContextualTyping1.ts, 20, 34)) +var b3: (name: string, num: number, boo: boolean) => void; +>b3 : (name: string, num: number, boo: boolean) => void, Symbol(b3, Decl(functionExpressionContextualTyping1.ts, 32, 3)) +>name : string, Symbol(name, Decl(functionExpressionContextualTyping1.ts, 32, 9)) +>num : number, Symbol(num, Decl(functionExpressionContextualTyping1.ts, 32, 22)) +>boo : boolean, Symbol(boo, Decl(functionExpressionContextualTyping1.ts, 32, 35)) -j = (name, number) => { }; ->j = (name, number) => { } : (name: string, number: number) => void ->j : (name: string, num: number, boo: boolean) => void, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 20, 3)) +b3 = (name, number) => { }; +>b3 = (name, number) => { } : (name: string, number: number) => void +>b3 : (name: string, num: number, boo: boolean) => void, Symbol(b3, Decl(functionExpressionContextualTyping1.ts, 32, 3)) >(name, number) => { } : (name: string, number: number) => void ->name : string, Symbol(name, Decl(functionExpressionContextualTyping1.ts, 21, 5)) ->number : number, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 21, 10)) +>name : string, Symbol(name, Decl(functionExpressionContextualTyping1.ts, 33, 6)) +>number : number, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 33, 11)) -var k: (n: E) => string = (number = 1) => { return "hello"; }; ->k : (n: E) => string, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 23, 3)) ->n : E, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 23, 8)) +var b4: (n: E) => string = (number = 1) => { return "hello"; }; +>b4 : (n: E) => string, Symbol(b4, Decl(functionExpressionContextualTyping1.ts, 35, 3)) +>n : E, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 35, 9)) >E : E, Symbol(E, Decl(functionExpressionContextualTyping1.ts, 0, 0)) >(number = 1) => { return "hello"; } : (number?: E) => string ->number : E, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 23, 27)) +>number : E, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 35, 28)) >1 : number >"hello" : string -var k1: (n: {}) => string = (number = 1) => { return "hello"; }; ->k1 : (n: {}) => string, Symbol(k1, Decl(functionExpressionContextualTyping1.ts, 24, 3)) ->n : {}, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 24, 9)) ->(number = 1) => { return "hello"; } : (number?: {}) => string ->number : {}, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 24, 29)) ->1 : number +var b5: (n: {}) => string = (number = "string") => { return "hello"; }; +>b5 : (n: {}) => string, Symbol(b5, Decl(functionExpressionContextualTyping1.ts, 36, 3)) +>n : {}, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 36, 9)) +>(number = "string") => { return "hello"; } : (number?: {}) => string +>number : {}, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 36, 29)) +>"string" : string >"hello" : string +// A contextual signature S is extracted from a function type T as follows: +// Otherwise, no contextual signature can be extracted from T and S is undefined. +var b6: ((s: string, w: boolean) => void) | ((n: number) => number); +>b6 : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(b6, Decl(functionExpressionContextualTyping1.ts, 40, 3)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 40, 10)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 40, 20)) +>n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 40, 46)) + +var b7: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); +>b7 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(b7, Decl(functionExpressionContextualTyping1.ts, 41, 3)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 41, 10)) +>w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 41, 20)) +>s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 41, 46)) +>w : number, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 41, 56)) + +b6 = (k) => { k.toLowerCase() }; +>b6 = (k) => { k.toLowerCase() } : (k: any) => void +>b6 : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(b6, Decl(functionExpressionContextualTyping1.ts, 40, 3)) +>(k) => { k.toLowerCase() } : (k: any) => void +>k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 42, 6)) +>k.toLowerCase() : any +>k.toLowerCase : any +>k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 42, 6)) +>toLowerCase : any + +b6 = (i) => { +>b6 = (i) => { i.toExponential(); return i;} : (i: any) => any +>b6 : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(b6, Decl(functionExpressionContextualTyping1.ts, 40, 3)) +>(i) => { i.toExponential(); return i;} : (i: any) => any +>i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 43, 6)) + + i.toExponential(); +>i.toExponential() : any +>i.toExponential : any +>i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 43, 6)) +>toExponential : any + + return i; +>i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 43, 6)) + +}; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) +b7 = (j, m) => { }; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) +>b7 = (j, m) => { } : (j: any, m: any) => void +>b7 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(b7, Decl(functionExpressionContextualTyping1.ts, 41, 3)) +>(j, m) => { } : (j: any, m: any) => void +>j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 47, 6)) +>m : any, Symbol(m, Decl(functionExpressionContextualTyping1.ts, 47, 8)) + class C { ->C : C, Symbol(C, Decl(functionExpressionContextualTyping1.ts, 24, 64)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 25, 8)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 25, 10)) +>C : C, Symbol(C, Decl(functionExpressionContextualTyping1.ts, 47, 19)) +>T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 49, 8)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) constructor() { var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { ->k : ((j: T, k: U) => (T | U)[]) | ((j: number, k: U) => number[]), Symbol(k, Decl(functionExpressionContextualTyping1.ts, 27, 11)) ->j : T, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 27, 17)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 25, 8)) ->k : U, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 27, 22)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 25, 10)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 25, 8)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 25, 10)) ->j : number, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 27, 45)) ->k : U, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 27, 55)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 25, 10)) +>k : ((j: T, k: U) => (T | U)[]) | ((j: number, k: U) => number[]), Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 11)) +>j : T, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 17)) +>T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 49, 8)) +>k : U, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 22)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) +>T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 49, 8)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) +>j : number, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 45)) +>k : U, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 55)) +>U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) >(j, k) => { return [j, k]; } : (j: any, k: any) => any[] ->j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 27, 77)) ->k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 27, 79)) +>j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 77)) +>k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 79)) return [j, k]; >[j, k] : any[] ->j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 27, 77)) ->k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 27, 79)) +>j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 77)) +>k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 79)) } // Per spec, no contextual signature can be extracted in this case. } diff --git a/tests/baselines/reference/functionExpressionContextualTyping2.errors.txt b/tests/baselines/reference/functionExpressionContextualTyping2.errors.txt index d9622c50e420d..6a3a7998f099d 100644 --- a/tests/baselines/reference/functionExpressionContextualTyping2.errors.txt +++ b/tests/baselines/reference/functionExpressionContextualTyping2.errors.txt @@ -1,36 +1,21 @@ -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(3,1): error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. +tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(11,1): error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. Type 'boolean' is not assignable to type 'string'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(5,7): error TS2300: Duplicate identifier 'C'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(8,7): error TS2300: Duplicate identifier 'C'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(10,43): error TS2322: Type 'number' is not assignable to type 'T'. -tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts(10,50): error TS2322: Type 'number' is not assignable to type 'U'. -==== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts (5 errors) ==== - var g0: (n: number, s: string) => number - var i: typeof g0 | ((n: number, s: string) => string); - i = (foo, bar) => { return true; } - ~ +==== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts (1 errors) ==== + // A contextual signature S is extracted from a function type T as follows: + // If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature. + // If T is a union type, let U be the set of element types in T that have call signatures. + // If each type in U has exactly one call signature and that call signature is non- generic, + // and if all of the signatures are identical ignoring return types, then S is a signature + // with the same parameters and a union of the return types. + // Otherwise, no contextual signature can be extracted from T and S is undefined. + + var a0: (n: number, s: string) => number + var a1: typeof a0 | ((n: number, s: string) => string); + a1 = (foo, bar) => { return true; } // Error + ~~ !!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '((n: number, s: string) => number) | ((n: number, s: string) => string)'. !!! error TS2322: Type '(foo: number, bar: string) => boolean' is not assignable to type '(n: number, s: string) => string'. -!!! error TS2322: Type 'boolean' is not assignable to type 'string'. - - class C { } - ~ -!!! error TS2300: Duplicate identifier 'C'. - - var j: (c: C) => number = (j) => { return 1; } - class C { - ~ -!!! error TS2300: Duplicate identifier 'C'. - constructor() { - var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { - ~~~~~ -!!! error TS2322: Type 'number' is not assignable to type 'T'. - ~~~~~ -!!! error TS2322: Type 'number' is not assignable to type 'U'. - return [j, k]; - } - } - } \ No newline at end of file +!!! error TS2322: Type 'boolean' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/functionExpressionContextualTyping2.js b/tests/baselines/reference/functionExpressionContextualTyping2.js index 87d3e1ed9efaf..dae30a790360b 100644 --- a/tests/baselines/reference/functionExpressionContextualTyping2.js +++ b/tests/baselines/reference/functionExpressionContextualTyping2.js @@ -1,36 +1,24 @@ //// [functionExpressionContextualTyping2.ts] -var g0: (n: number, s: string) => number -var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return true; } +// A contextual signature S is extracted from a function type T as follows: +// If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature. +// If T is a union type, let U be the set of element types in T that have call signatures. +// If each type in U has exactly one call signature and that call signature is non- generic, +// and if all of the signatures are identical ignoring return types, then S is a signature +// with the same parameters and a union of the return types. +// Otherwise, no contextual signature can be extracted from T and S is undefined. -class C { } - -var j: (c: C) => number = (j) => { return 1; } -class C { - constructor() { - var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { - return [j, k]; - } - } -} +var a0: (n: number, s: string) => number +var a1: typeof a0 | ((n: number, s: string) => string); +a1 = (foo, bar) => { return true; } // Error //// [functionExpressionContextualTyping2.js] -var g0; -var i; -i = function (foo, bar) { return true; }; -var C = (function () { - function C() { - } - return C; -})(); -var j = function (j) { return 1; }; -var C = (function () { - function C() { - var k = function (j, k) { - if (j === void 0) { j = 1; } - if (k === void 0) { k = 0; } - return [j, k]; - }; - } - return C; -})(); +// A contextual signature S is extracted from a function type T as follows: +// If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature. +// If T is a union type, let U be the set of element types in T that have call signatures. +// If each type in U has exactly one call signature and that call signature is non- generic, +// and if all of the signatures are identical ignoring return types, then S is a signature +// with the same parameters and a union of the return types. +// Otherwise, no contextual signature can be extracted from T and S is undefined. +var a0; +var a1; +a1 = function (foo, bar) { return true; }; // Error diff --git a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts index 1ede1c3fa7285..ea8e60cb5b922 100644 --- a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts +++ b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts @@ -1,28 +1,52 @@ -enum E { red, blue } +// When a function expression with no type parameters and no parameter type annotations +// is contextually typed (section 4.19) by a type T and a contextual signature S can be extracted from T -var g0: (n: number, s:string) => number; -var g: ((s: string, w: boolean) => void) | ((n: number) => number); -var g1: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); +enum E { red, blue } -g1 = (j, m) => { } // Per spec, no contextual signature can be extracted in this case. -g = (k, h=true) => { k.toLowerCase() }; -g = (k) => { k.toLowerCase() }; -g = (i) => { - i.toExponential(); - return i; -}; // Per spec, no contextual signature can be extracted in this case. +// A contextual signature S is extracted from a function type T as follows: +// If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature. + +var a0: (n: number, s: string) => number = (num, str) => { + num.toExponential(); + return 0; +} + +class Class { + foo() { } +} -var h: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); -h = (k, h) => { }; +var a1: (c: Class) => number = (a1) => { + a1.foo(); + return 1; +} -var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return foo + 1; } -i = (foo, bar) => { return "hello"; } -var j: (name: string, num: number, boo: boolean) => void; -j = (name, number) => { }; +// A contextual signature S is extracted from a function type T as follows: +// If T is a union type, let U be the set of element types in T that have call signatures. +// If each type in U has exactly one call signature and that call signature is non- generic, +// and if all of the signatures are identical ignoring return types, +// then S is a signature with the same parameters and a union of the return types. +var b1: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +b1 = (k, h) => { }; +var b2: typeof a0 | ((n: number, s: string) => string); +b2 = (foo, bar) => { return foo + 1; } +b2 = (foo, bar) => { return "hello"; } +var b3: (name: string, num: number, boo: boolean) => void; +b3 = (name, number) => { }; + +var b4: (n: E) => string = (number = 1) => { return "hello"; }; +var b5: (n: {}) => string = (number = "string") => { return "hello"; }; + +// A contextual signature S is extracted from a function type T as follows: +// Otherwise, no contextual signature can be extracted from T and S is undefined. +var b6: ((s: string, w: boolean) => void) | ((n: number) => number); +var b7: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); +b6 = (k) => { k.toLowerCase() }; +b6 = (i) => { + i.toExponential(); + return i; +}; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) +b7 = (j, m) => { }; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) -var k: (n: E) => string = (number = 1) => { return "hello"; }; -var k1: (n: {}) => string = (number = 1) => { return "hello"; }; class C { constructor() { var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { diff --git a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts index d22fff7e1387b..1b88c1a8cfbdc 100644 --- a/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts +++ b/tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping2.ts @@ -1,14 +1,11 @@ -var g0: (n: number, s: string) => number -var i: typeof g0 | ((n: number, s: string) => string); -i = (foo, bar) => { return true; } +// A contextual signature S is extracted from a function type T as follows: +// If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature. +// If T is a union type, let U be the set of element types in T that have call signatures. +// If each type in U has exactly one call signature and that call signature is non- generic, +// and if all of the signatures are identical ignoring return types, then S is a signature +// with the same parameters and a union of the return types. +// Otherwise, no contextual signature can be extracted from T and S is undefined. -class C { } - -var j: (c: C) => number = (j) => { return 1; } -class C { - constructor() { - var k: (j: T, k: U) => (T|U)[] = (j = 1, k = 0) => { - return [j, k]; - } - } -} \ No newline at end of file +var a0: (n: number, s: string) => number +var a1: typeof a0 | ((n: number, s: string) => string); +a1 = (foo, bar) => { return true; } // Error \ No newline at end of file From 1266b0d1d4c19b9d997c38ba404ae0cc4b78c483 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Apr 2015 15:52:20 -0700 Subject: [PATCH 6/7] Update baselines from merge master --- .../functionExpressionContextualTyping1.types | 182 +++++++++--------- 1 file changed, 91 insertions(+), 91 deletions(-) diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.types b/tests/baselines/reference/functionExpressionContextualTyping1.types index f7f04d5ed0fd2..61d16bf6a4fdd 100644 --- a/tests/baselines/reference/functionExpressionContextualTyping1.types +++ b/tests/baselines/reference/functionExpressionContextualTyping1.types @@ -3,52 +3,52 @@ // is contextually typed (section 4.19) by a type T and a contextual signature S can be extracted from T enum E { red, blue } ->E : E, Symbol(E, Decl(functionExpressionContextualTyping1.ts, 0, 0)) ->red : E, Symbol(E.red, Decl(functionExpressionContextualTyping1.ts, 3, 8)) ->blue : E, Symbol(E.blue, Decl(functionExpressionContextualTyping1.ts, 3, 13)) +>E : E +>red : E +>blue : E // A contextual signature S is extracted from a function type T as follows: // If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature. var a0: (n: number, s: string) => number = (num, str) => { ->a0 : (n: number, s: string) => number, Symbol(a0, Decl(functionExpressionContextualTyping1.ts, 8, 3)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 8, 9)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 8, 19)) +>a0 : (n: number, s: string) => number +>n : number +>s : string >(num, str) => { num.toExponential(); return 0;} : (num: number, str: string) => number ->num : number, Symbol(num, Decl(functionExpressionContextualTyping1.ts, 8, 44)) ->str : string, Symbol(str, Decl(functionExpressionContextualTyping1.ts, 8, 48)) +>num : number +>str : string num.toExponential(); >num.toExponential() : string ->num.toExponential : (fractionDigits?: number) => string, Symbol(Number.toExponential, Decl(lib.d.ts, 469, 45)) ->num : number, Symbol(num, Decl(functionExpressionContextualTyping1.ts, 8, 44)) ->toExponential : (fractionDigits?: number) => string, Symbol(Number.toExponential, Decl(lib.d.ts, 469, 45)) +>num.toExponential : (fractionDigits?: number) => string +>num : number +>toExponential : (fractionDigits?: number) => string return 0; >0 : number } class Class { ->Class : Class, Symbol(Class, Decl(functionExpressionContextualTyping1.ts, 11, 1)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 13, 12)) +>Class : Class +>T : T foo() { } ->foo : () => void, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 13, 16)) +>foo : () => void } var a1: (c: Class) => number = (a1) => { ->a1 : (c: Class) => number, Symbol(a1, Decl(functionExpressionContextualTyping1.ts, 17, 3)) ->c : Class, Symbol(c, Decl(functionExpressionContextualTyping1.ts, 17, 9)) ->Class : Class, Symbol(Class, Decl(functionExpressionContextualTyping1.ts, 11, 1)) ->Number : Number, Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) +>a1 : (c: Class) => number +>c : Class +>Class : Class +>Number : Number >(a1) => { a1.foo(); return 1;} : (a1: Class) => number ->a1 : Class, Symbol(a1, Decl(functionExpressionContextualTyping1.ts, 17, 40)) +>a1 : Class a1.foo(); >a1.foo() : void ->a1.foo : () => void, Symbol(Class.foo, Decl(functionExpressionContextualTyping1.ts, 13, 16)) ->a1 : Class, Symbol(a1, Decl(functionExpressionContextualTyping1.ts, 17, 40)) ->foo : () => void, Symbol(Class.foo, Decl(functionExpressionContextualTyping1.ts, 13, 16)) +>a1.foo : () => void +>a1 : Class +>foo : () => void return 1; >1 : number @@ -60,146 +60,146 @@ var a1: (c: Class) => number = (a1) => { // and if all of the signatures are identical ignoring return types, // then S is a signature with the same parameters and a union of the return types. var b1: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); ->b1 : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(b1, Decl(functionExpressionContextualTyping1.ts, 27, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 27, 10)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 27, 20)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 27, 46)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 27, 56)) +>b1 : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string) +>s : string +>w : boolean +>s : string +>w : boolean b1 = (k, h) => { }; >b1 = (k, h) => { } : (k: string, h: boolean) => void ->b1 : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string), Symbol(b1, Decl(functionExpressionContextualTyping1.ts, 27, 3)) +>b1 : ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string) >(k, h) => { } : (k: string, h: boolean) => void ->k : string, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 28, 6)) ->h : boolean, Symbol(h, Decl(functionExpressionContextualTyping1.ts, 28, 8)) +>k : string +>h : boolean var b2: typeof a0 | ((n: number, s: string) => string); ->b2 : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(b2, Decl(functionExpressionContextualTyping1.ts, 29, 3)) ->a0 : (n: number, s: string) => number, Symbol(a0, Decl(functionExpressionContextualTyping1.ts, 8, 3)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 29, 22)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 29, 32)) +>b2 : ((n: number, s: string) => number) | ((n: number, s: string) => string) +>a0 : (n: number, s: string) => number +>n : number +>s : string b2 = (foo, bar) => { return foo + 1; } >b2 = (foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number ->b2 : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(b2, Decl(functionExpressionContextualTyping1.ts, 29, 3)) +>b2 : ((n: number, s: string) => number) | ((n: number, s: string) => string) >(foo, bar) => { return foo + 1; } : (foo: number, bar: string) => number ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 30, 6)) ->bar : string, Symbol(bar, Decl(functionExpressionContextualTyping1.ts, 30, 10)) +>foo : number +>bar : string >foo + 1 : number ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 30, 6)) +>foo : number >1 : number b2 = (foo, bar) => { return "hello"; } >b2 = (foo, bar) => { return "hello"; } : (foo: number, bar: string) => string ->b2 : ((n: number, s: string) => number) | ((n: number, s: string) => string), Symbol(b2, Decl(functionExpressionContextualTyping1.ts, 29, 3)) +>b2 : ((n: number, s: string) => number) | ((n: number, s: string) => string) >(foo, bar) => { return "hello"; } : (foo: number, bar: string) => string ->foo : number, Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 31, 6)) ->bar : string, Symbol(bar, Decl(functionExpressionContextualTyping1.ts, 31, 10)) +>foo : number +>bar : string >"hello" : string var b3: (name: string, num: number, boo: boolean) => void; ->b3 : (name: string, num: number, boo: boolean) => void, Symbol(b3, Decl(functionExpressionContextualTyping1.ts, 32, 3)) ->name : string, Symbol(name, Decl(functionExpressionContextualTyping1.ts, 32, 9)) ->num : number, Symbol(num, Decl(functionExpressionContextualTyping1.ts, 32, 22)) ->boo : boolean, Symbol(boo, Decl(functionExpressionContextualTyping1.ts, 32, 35)) +>b3 : (name: string, num: number, boo: boolean) => void +>name : string +>num : number +>boo : boolean b3 = (name, number) => { }; >b3 = (name, number) => { } : (name: string, number: number) => void ->b3 : (name: string, num: number, boo: boolean) => void, Symbol(b3, Decl(functionExpressionContextualTyping1.ts, 32, 3)) +>b3 : (name: string, num: number, boo: boolean) => void >(name, number) => { } : (name: string, number: number) => void ->name : string, Symbol(name, Decl(functionExpressionContextualTyping1.ts, 33, 6)) ->number : number, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 33, 11)) +>name : string +>number : number var b4: (n: E) => string = (number = 1) => { return "hello"; }; ->b4 : (n: E) => string, Symbol(b4, Decl(functionExpressionContextualTyping1.ts, 35, 3)) ->n : E, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 35, 9)) ->E : E, Symbol(E, Decl(functionExpressionContextualTyping1.ts, 0, 0)) +>b4 : (n: E) => string +>n : E +>E : E >(number = 1) => { return "hello"; } : (number?: E) => string ->number : E, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 35, 28)) +>number : E >1 : number >"hello" : string var b5: (n: {}) => string = (number = "string") => { return "hello"; }; ->b5 : (n: {}) => string, Symbol(b5, Decl(functionExpressionContextualTyping1.ts, 36, 3)) ->n : {}, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 36, 9)) +>b5 : (n: {}) => string +>n : {} >(number = "string") => { return "hello"; } : (number?: {}) => string ->number : {}, Symbol(number, Decl(functionExpressionContextualTyping1.ts, 36, 29)) +>number : {} >"string" : string >"hello" : string // A contextual signature S is extracted from a function type T as follows: // Otherwise, no contextual signature can be extracted from T and S is undefined. var b6: ((s: string, w: boolean) => void) | ((n: number) => number); ->b6 : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(b6, Decl(functionExpressionContextualTyping1.ts, 40, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 40, 10)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 40, 20)) ->n : number, Symbol(n, Decl(functionExpressionContextualTyping1.ts, 40, 46)) +>b6 : ((s: string, w: boolean) => void) | ((n: number) => number) +>s : string +>w : boolean +>n : number var b7: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); ->b7 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(b7, Decl(functionExpressionContextualTyping1.ts, 41, 3)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 41, 10)) ->w : boolean, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 41, 20)) ->s : string, Symbol(s, Decl(functionExpressionContextualTyping1.ts, 41, 46)) ->w : number, Symbol(w, Decl(functionExpressionContextualTyping1.ts, 41, 56)) +>b7 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string) +>s : string +>w : boolean +>s : string +>w : number b6 = (k) => { k.toLowerCase() }; >b6 = (k) => { k.toLowerCase() } : (k: any) => void ->b6 : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(b6, Decl(functionExpressionContextualTyping1.ts, 40, 3)) +>b6 : ((s: string, w: boolean) => void) | ((n: number) => number) >(k) => { k.toLowerCase() } : (k: any) => void ->k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 42, 6)) +>k : any >k.toLowerCase() : any >k.toLowerCase : any ->k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 42, 6)) +>k : any >toLowerCase : any b6 = (i) => { >b6 = (i) => { i.toExponential(); return i;} : (i: any) => any ->b6 : ((s: string, w: boolean) => void) | ((n: number) => number), Symbol(b6, Decl(functionExpressionContextualTyping1.ts, 40, 3)) +>b6 : ((s: string, w: boolean) => void) | ((n: number) => number) >(i) => { i.toExponential(); return i;} : (i: any) => any ->i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 43, 6)) +>i : any i.toExponential(); >i.toExponential() : any >i.toExponential : any ->i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 43, 6)) +>i : any >toExponential : any return i; ->i : any, Symbol(i, Decl(functionExpressionContextualTyping1.ts, 43, 6)) +>i : any }; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) b7 = (j, m) => { }; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) >b7 = (j, m) => { } : (j: any, m: any) => void ->b7 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string), Symbol(b7, Decl(functionExpressionContextualTyping1.ts, 41, 3)) +>b7 : ((s: string, w: boolean) => void) | ((s: string, w: number) => string) >(j, m) => { } : (j: any, m: any) => void ->j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 47, 6)) ->m : any, Symbol(m, Decl(functionExpressionContextualTyping1.ts, 47, 8)) +>j : any +>m : any class C { ->C : C, Symbol(C, Decl(functionExpressionContextualTyping1.ts, 47, 19)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 49, 8)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) +>C : C +>T : T +>U : U constructor() { var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { ->k : ((j: T, k: U) => (T | U)[]) | ((j: number, k: U) => number[]), Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 11)) ->j : T, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 17)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 49, 8)) ->k : U, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 22)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) ->T : T, Symbol(T, Decl(functionExpressionContextualTyping1.ts, 49, 8)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) ->j : number, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 45)) ->k : U, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 55)) ->U : U, Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) +>k : ((j: T, k: U) => (T | U)[]) | ((j: number, k: U) => number[]) +>j : T +>T : T +>k : U +>U : U +>T : T +>U : U +>j : number +>k : U +>U : U >(j, k) => { return [j, k]; } : (j: any, k: any) => any[] ->j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 77)) ->k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 79)) +>j : any +>k : any return [j, k]; >[j, k] : any[] ->j : any, Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 77)) ->k : any, Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 79)) +>j : any +>k : any } // Per spec, no contextual signature can be extracted in this case. } From 94ed1d894206f444435ba03879607d541f7eb6b8 Mon Sep 17 00:00:00 2001 From: Yui T Date: Thu, 16 Apr 2015 16:03:09 -0700 Subject: [PATCH 7/7] update baselines from merge master --- ...unctionExpressionContextualTyping1.symbols | 169 ++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 tests/baselines/reference/functionExpressionContextualTyping1.symbols diff --git a/tests/baselines/reference/functionExpressionContextualTyping1.symbols b/tests/baselines/reference/functionExpressionContextualTyping1.symbols new file mode 100644 index 0000000000000..6182e4bb9a8e4 --- /dev/null +++ b/tests/baselines/reference/functionExpressionContextualTyping1.symbols @@ -0,0 +1,169 @@ +=== tests/cases/conformance/expressions/contextualTyping/functionExpressionContextualTyping1.ts === +// When a function expression with no type parameters and no parameter type annotations +// is contextually typed (section 4.19) by a type T and a contextual signature S can be extracted from T + +enum E { red, blue } +>E : Symbol(E, Decl(functionExpressionContextualTyping1.ts, 0, 0)) +>red : Symbol(E.red, Decl(functionExpressionContextualTyping1.ts, 3, 8)) +>blue : Symbol(E.blue, Decl(functionExpressionContextualTyping1.ts, 3, 13)) + +// A contextual signature S is extracted from a function type T as follows: +// If T is a function type with exactly one call signature, and if that call signature is non- generic, S is that signature. + +var a0: (n: number, s: string) => number = (num, str) => { +>a0 : Symbol(a0, Decl(functionExpressionContextualTyping1.ts, 8, 3)) +>n : Symbol(n, Decl(functionExpressionContextualTyping1.ts, 8, 9)) +>s : Symbol(s, Decl(functionExpressionContextualTyping1.ts, 8, 19)) +>num : Symbol(num, Decl(functionExpressionContextualTyping1.ts, 8, 44)) +>str : Symbol(str, Decl(functionExpressionContextualTyping1.ts, 8, 48)) + + num.toExponential(); +>num.toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, 469, 45)) +>num : Symbol(num, Decl(functionExpressionContextualTyping1.ts, 8, 44)) +>toExponential : Symbol(Number.toExponential, Decl(lib.d.ts, 469, 45)) + + return 0; +} + +class Class { +>Class : Symbol(Class, Decl(functionExpressionContextualTyping1.ts, 11, 1)) +>T : Symbol(T, Decl(functionExpressionContextualTyping1.ts, 13, 12)) + + foo() { } +>foo : Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 13, 16)) +} + +var a1: (c: Class) => number = (a1) => { +>a1 : Symbol(a1, Decl(functionExpressionContextualTyping1.ts, 17, 3)) +>c : Symbol(c, Decl(functionExpressionContextualTyping1.ts, 17, 9)) +>Class : Symbol(Class, Decl(functionExpressionContextualTyping1.ts, 11, 1)) +>Number : Symbol(Number, Decl(lib.d.ts, 456, 40), Decl(lib.d.ts, 518, 11)) +>a1 : Symbol(a1, Decl(functionExpressionContextualTyping1.ts, 17, 40)) + + a1.foo(); +>a1.foo : Symbol(Class.foo, Decl(functionExpressionContextualTyping1.ts, 13, 16)) +>a1 : Symbol(a1, Decl(functionExpressionContextualTyping1.ts, 17, 40)) +>foo : Symbol(Class.foo, Decl(functionExpressionContextualTyping1.ts, 13, 16)) + + return 1; +} + +// A contextual signature S is extracted from a function type T as follows: +// If T is a union type, let U be the set of element types in T that have call signatures. +// If each type in U has exactly one call signature and that call signature is non- generic, +// and if all of the signatures are identical ignoring return types, +// then S is a signature with the same parameters and a union of the return types. +var b1: ((s: string, w: boolean) => void) | ((s: string, w: boolean) => string); +>b1 : Symbol(b1, Decl(functionExpressionContextualTyping1.ts, 27, 3)) +>s : Symbol(s, Decl(functionExpressionContextualTyping1.ts, 27, 10)) +>w : Symbol(w, Decl(functionExpressionContextualTyping1.ts, 27, 20)) +>s : Symbol(s, Decl(functionExpressionContextualTyping1.ts, 27, 46)) +>w : Symbol(w, Decl(functionExpressionContextualTyping1.ts, 27, 56)) + +b1 = (k, h) => { }; +>b1 : Symbol(b1, Decl(functionExpressionContextualTyping1.ts, 27, 3)) +>k : Symbol(k, Decl(functionExpressionContextualTyping1.ts, 28, 6)) +>h : Symbol(h, Decl(functionExpressionContextualTyping1.ts, 28, 8)) + +var b2: typeof a0 | ((n: number, s: string) => string); +>b2 : Symbol(b2, Decl(functionExpressionContextualTyping1.ts, 29, 3)) +>a0 : Symbol(a0, Decl(functionExpressionContextualTyping1.ts, 8, 3)) +>n : Symbol(n, Decl(functionExpressionContextualTyping1.ts, 29, 22)) +>s : Symbol(s, Decl(functionExpressionContextualTyping1.ts, 29, 32)) + +b2 = (foo, bar) => { return foo + 1; } +>b2 : Symbol(b2, Decl(functionExpressionContextualTyping1.ts, 29, 3)) +>foo : Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 30, 6)) +>bar : Symbol(bar, Decl(functionExpressionContextualTyping1.ts, 30, 10)) +>foo : Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 30, 6)) + +b2 = (foo, bar) => { return "hello"; } +>b2 : Symbol(b2, Decl(functionExpressionContextualTyping1.ts, 29, 3)) +>foo : Symbol(foo, Decl(functionExpressionContextualTyping1.ts, 31, 6)) +>bar : Symbol(bar, Decl(functionExpressionContextualTyping1.ts, 31, 10)) + +var b3: (name: string, num: number, boo: boolean) => void; +>b3 : Symbol(b3, Decl(functionExpressionContextualTyping1.ts, 32, 3)) +>name : Symbol(name, Decl(functionExpressionContextualTyping1.ts, 32, 9)) +>num : Symbol(num, Decl(functionExpressionContextualTyping1.ts, 32, 22)) +>boo : Symbol(boo, Decl(functionExpressionContextualTyping1.ts, 32, 35)) + +b3 = (name, number) => { }; +>b3 : Symbol(b3, Decl(functionExpressionContextualTyping1.ts, 32, 3)) +>name : Symbol(name, Decl(functionExpressionContextualTyping1.ts, 33, 6)) +>number : Symbol(number, Decl(functionExpressionContextualTyping1.ts, 33, 11)) + +var b4: (n: E) => string = (number = 1) => { return "hello"; }; +>b4 : Symbol(b4, Decl(functionExpressionContextualTyping1.ts, 35, 3)) +>n : Symbol(n, Decl(functionExpressionContextualTyping1.ts, 35, 9)) +>E : Symbol(E, Decl(functionExpressionContextualTyping1.ts, 0, 0)) +>number : Symbol(number, Decl(functionExpressionContextualTyping1.ts, 35, 28)) + +var b5: (n: {}) => string = (number = "string") => { return "hello"; }; +>b5 : Symbol(b5, Decl(functionExpressionContextualTyping1.ts, 36, 3)) +>n : Symbol(n, Decl(functionExpressionContextualTyping1.ts, 36, 9)) +>number : Symbol(number, Decl(functionExpressionContextualTyping1.ts, 36, 29)) + +// A contextual signature S is extracted from a function type T as follows: +// Otherwise, no contextual signature can be extracted from T and S is undefined. +var b6: ((s: string, w: boolean) => void) | ((n: number) => number); +>b6 : Symbol(b6, Decl(functionExpressionContextualTyping1.ts, 40, 3)) +>s : Symbol(s, Decl(functionExpressionContextualTyping1.ts, 40, 10)) +>w : Symbol(w, Decl(functionExpressionContextualTyping1.ts, 40, 20)) +>n : Symbol(n, Decl(functionExpressionContextualTyping1.ts, 40, 46)) + +var b7: ((s: string, w: boolean) => void) | ((s: string, w: number) => string); +>b7 : Symbol(b7, Decl(functionExpressionContextualTyping1.ts, 41, 3)) +>s : Symbol(s, Decl(functionExpressionContextualTyping1.ts, 41, 10)) +>w : Symbol(w, Decl(functionExpressionContextualTyping1.ts, 41, 20)) +>s : Symbol(s, Decl(functionExpressionContextualTyping1.ts, 41, 46)) +>w : Symbol(w, Decl(functionExpressionContextualTyping1.ts, 41, 56)) + +b6 = (k) => { k.toLowerCase() }; +>b6 : Symbol(b6, Decl(functionExpressionContextualTyping1.ts, 40, 3)) +>k : Symbol(k, Decl(functionExpressionContextualTyping1.ts, 42, 6)) +>k : Symbol(k, Decl(functionExpressionContextualTyping1.ts, 42, 6)) + +b6 = (i) => { +>b6 : Symbol(b6, Decl(functionExpressionContextualTyping1.ts, 40, 3)) +>i : Symbol(i, Decl(functionExpressionContextualTyping1.ts, 43, 6)) + + i.toExponential(); +>i : Symbol(i, Decl(functionExpressionContextualTyping1.ts, 43, 6)) + + return i; +>i : Symbol(i, Decl(functionExpressionContextualTyping1.ts, 43, 6)) + +}; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) +b7 = (j, m) => { }; // Per spec, no contextual signature can be extracted in this case. (Otherwise clause) +>b7 : Symbol(b7, Decl(functionExpressionContextualTyping1.ts, 41, 3)) +>j : Symbol(j, Decl(functionExpressionContextualTyping1.ts, 47, 6)) +>m : Symbol(m, Decl(functionExpressionContextualTyping1.ts, 47, 8)) + +class C { +>C : Symbol(C, Decl(functionExpressionContextualTyping1.ts, 47, 19)) +>T : Symbol(T, Decl(functionExpressionContextualTyping1.ts, 49, 8)) +>U : Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) + + constructor() { + var k: ((j: T, k: U) => (T|U)[]) | ((j: number,k :U) => number[]) = (j, k) => { +>k : Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 11)) +>j : Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 17)) +>T : Symbol(T, Decl(functionExpressionContextualTyping1.ts, 49, 8)) +>k : Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 22)) +>U : Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) +>T : Symbol(T, Decl(functionExpressionContextualTyping1.ts, 49, 8)) +>U : Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) +>j : Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 45)) +>k : Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 55)) +>U : Symbol(U, Decl(functionExpressionContextualTyping1.ts, 49, 10)) +>j : Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 77)) +>k : Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 79)) + + return [j, k]; +>j : Symbol(j, Decl(functionExpressionContextualTyping1.ts, 51, 77)) +>k : Symbol(k, Decl(functionExpressionContextualTyping1.ts, 51, 79)) + + } // Per spec, no contextual signature can be extracted in this case. + } +}