From f4a07aecdc1f9dedbeaf5e974bf3899b9c107b21 Mon Sep 17 00:00:00 2001 From: Kevin Donnelly Date: Sat, 2 Jun 2018 11:14:18 -0500 Subject: [PATCH 1/4] Add some tests for existing behavior inferring from generic functions. --- ...TypeParameterEquivalence2strict.errors.txt | 89 + .../genericTypeParameterEquivalence2strict.js | 122 + ...ricTypeParameterEquivalence2strict.symbols | 215 ++ ...nericTypeParameterEquivalence2strict.types | 241 ++ ...icFunctionsFromGenericFunctions.errors.txt | 68 + ...ingGenericFunctionsFromGenericFunctions.js | 53 + ...nericFunctionsFromGenericFunctions.symbols | 135 ++ ...GenericFunctionsFromGenericFunctions.types | 145 ++ ...cFunctionsFromGenericFunctions2.errors.txt | 627 ++++++ ...ngGenericFunctionsFromGenericFunctions2.js | 622 ++++++ ...ericFunctionsFromGenericFunctions2.symbols | 1706 ++++++++++++++ ...enericFunctionsFromGenericFunctions2.types | 1953 +++++++++++++++++ ...nsFromGenericFunctionsContexual.errors.txt | 192 ++ ...cFunctionsFromGenericFunctionsContexual.js | 156 ++ ...tionsFromGenericFunctionsContexual.symbols | 386 ++++ ...nctionsFromGenericFunctionsContexual.types | 458 ++++ .../genericTypeParameterEquivalence2strict.ts | 67 + ...ingGenericFunctionsFromGenericFunctions.ts | 34 + ...ngGenericFunctionsFromGenericFunctions2.ts | 368 ++++ ...cFunctionsFromGenericFunctionsContexual.ts | 89 + 20 files changed, 7726 insertions(+) create mode 100644 tests/baselines/reference/genericTypeParameterEquivalence2strict.errors.txt create mode 100644 tests/baselines/reference/genericTypeParameterEquivalence2strict.js create mode 100644 tests/baselines/reference/genericTypeParameterEquivalence2strict.symbols create mode 100644 tests/baselines/reference/genericTypeParameterEquivalence2strict.types create mode 100644 tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.errors.txt create mode 100644 tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.js create mode 100644 tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.symbols create mode 100644 tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.types create mode 100644 tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.errors.txt create mode 100644 tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.js create mode 100644 tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.symbols create mode 100644 tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.types create mode 100644 tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.errors.txt create mode 100644 tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.js create mode 100644 tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.symbols create mode 100644 tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.types create mode 100644 tests/cases/compiler/genericTypeParameterEquivalence2strict.ts create mode 100644 tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions.ts create mode 100644 tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts create mode 100644 tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts diff --git a/tests/baselines/reference/genericTypeParameterEquivalence2strict.errors.txt b/tests/baselines/reference/genericTypeParameterEquivalence2strict.errors.txt new file mode 100644 index 0000000000000..d2e24776fabe6 --- /dev/null +++ b/tests/baselines/reference/genericTypeParameterEquivalence2strict.errors.txt @@ -0,0 +1,89 @@ +tests/cases/compiler/genericTypeParameterEquivalence2strict.ts(41,22): error TS2345: Argument of type '(f: (a: A) => boolean, ar: A[]) => A[]' is not assignable to parameter of type '(a: {}, b: {}) => {}[]'. + Types of parameters 'f' and 'a' are incompatible. + Type '{}' is not assignable to type '(a: {}) => boolean'. + Type '{}' provides no match for the signature '(a: {}): boolean'. +tests/cases/compiler/genericTypeParameterEquivalence2strict.ts(59,20): error TS2345: Argument of type '(ar: A[]) => number' is not assignable to parameter of type '(b: {}) => number'. + Types of parameters 'ar' and 'b' are incompatible. + Type '{}' is not assignable to type '{}[]'. + Property 'length' is missing in type '{}'. +tests/cases/compiler/genericTypeParameterEquivalence2strict.ts(64,20): error TS2345: Argument of type '(ar: A[]) => number' is not assignable to parameter of type '(b: {}) => number'. + + +==== tests/cases/compiler/genericTypeParameterEquivalence2strict.ts (3 errors) ==== + // compose :: (b->c) -> (a->b) -> (a->c) + function compose(f: (b: B) => C, g: (a:A) => B): (a:A) => C { + return function (a:A) : C { + return f(g.apply(null, a)); + }; + } + + // forEach :: [a] -> (a -> ()) -> () + function forEach(list: A[], f: (a: A, n?: number) => void ): void { + for (var i = 0; i < list.length; ++i) { + f(list[i], i); + } + } + + // filter :: (a->bool) -> [a] -> [a] + function filter(f: (a: A) => boolean, ar: A[]): A[] { + var ret: A[] = []; + forEach(ar, (el) => { + if (f(el)) { + ret.push(el); + } + } ); + + return ret; + } + + // length :: [a] -> Num + function length2(ar: A[]): number { + return ar.length; + } + + // curry1 :: ((a,b)->c) -> (a->(b->c)) + function curry1(f: (a: A, b: B) => C): (ax: A) => (bx: B) => C { + return function (ay: A) { + return function (by: B) { + return f(ay, by); + }; + }; + } + + var cfilter = curry1(filter); + ~~~~~~ +!!! error TS2345: Argument of type '(f: (a: A) => boolean, ar: A[]) => A[]' is not assignable to parameter of type '(a: {}, b: {}) => {}[]'. +!!! error TS2345: Types of parameters 'f' and 'a' are incompatible. +!!! error TS2345: Type '{}' is not assignable to type '(a: {}) => boolean'. +!!! error TS2345: Type '{}' provides no match for the signature '(a: {}): boolean'. + + declare function strBool(str: string): boolean + const filterer = cfilter(strBool); + const expectFilterer: (a: string[]) => string[] = filterer; + + const filtered = filterer(["hello"]); + const expectFiltered: string[] = filtered; + + // compose :: (b->c) -> (a->b) -> (a->c) + // length :: [a] -> Num + // cfilter :: {} -> {} -> [{}] + // pred :: a -> Bool + // cfilter(pred) :: {} -> [{}] + // length2 :: [a] -> Num + // countWhere :: (a -> Bool) -> [a] -> Num + + function countWhere_1(pred: (a: A) => boolean): (a: A[]) => number { + return compose(length2, cfilter(pred)); + ~~~~~~~ +!!! error TS2345: Argument of type '(ar: A[]) => number' is not assignable to parameter of type '(b: {}) => number'. +!!! error TS2345: Types of parameters 'ar' and 'b' are incompatible. +!!! error TS2345: Type '{}' is not assignable to type '{}[]'. +!!! error TS2345: Property 'length' is missing in type '{}'. + } + + function countWhere_2(pred: (a: A) => boolean): (a: A[]) => number { + var where = cfilter(pred); + return compose(length2, where); + ~~~~~~~ +!!! error TS2345: Argument of type '(ar: A[]) => number' is not assignable to parameter of type '(b: {}) => number'. + } \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeParameterEquivalence2strict.js b/tests/baselines/reference/genericTypeParameterEquivalence2strict.js new file mode 100644 index 0000000000000..b3ab2cfe142de --- /dev/null +++ b/tests/baselines/reference/genericTypeParameterEquivalence2strict.js @@ -0,0 +1,122 @@ +//// [genericTypeParameterEquivalence2strict.ts] +// compose :: (b->c) -> (a->b) -> (a->c) +function compose(f: (b: B) => C, g: (a:A) => B): (a:A) => C { + return function (a:A) : C { + return f(g.apply(null, a)); + }; +} + +// forEach :: [a] -> (a -> ()) -> () +function forEach(list: A[], f: (a: A, n?: number) => void ): void { + for (var i = 0; i < list.length; ++i) { + f(list[i], i); + } +} + +// filter :: (a->bool) -> [a] -> [a] +function filter(f: (a: A) => boolean, ar: A[]): A[] { + var ret: A[] = []; + forEach(ar, (el) => { + if (f(el)) { + ret.push(el); + } + } ); + + return ret; +} + +// length :: [a] -> Num +function length2(ar: A[]): number { + return ar.length; +} + +// curry1 :: ((a,b)->c) -> (a->(b->c)) +function curry1(f: (a: A, b: B) => C): (ax: A) => (bx: B) => C { + return function (ay: A) { + return function (by: B) { + return f(ay, by); + }; + }; +} + +var cfilter = curry1(filter); + +declare function strBool(str: string): boolean +const filterer = cfilter(strBool); +const expectFilterer: (a: string[]) => string[] = filterer; + +const filtered = filterer(["hello"]); +const expectFiltered: string[] = filtered; + +// compose :: (b->c) -> (a->b) -> (a->c) +// length :: [a] -> Num +// cfilter :: {} -> {} -> [{}] +// pred :: a -> Bool +// cfilter(pred) :: {} -> [{}] +// length2 :: [a] -> Num +// countWhere :: (a -> Bool) -> [a] -> Num + +function countWhere_1(pred: (a: A) => boolean): (a: A[]) => number { + return compose(length2, cfilter(pred)); +} + +function countWhere_2(pred: (a: A) => boolean): (a: A[]) => number { + var where = cfilter(pred); + return compose(length2, where); +} + +//// [genericTypeParameterEquivalence2strict.js] +"use strict"; +// compose :: (b->c) -> (a->b) -> (a->c) +function compose(f, g) { + return function (a) { + return f(g.apply(null, a)); + }; +} +// forEach :: [a] -> (a -> ()) -> () +function forEach(list, f) { + for (var i = 0; i < list.length; ++i) { + f(list[i], i); + } +} +// filter :: (a->bool) -> [a] -> [a] +function filter(f, ar) { + var ret = []; + forEach(ar, function (el) { + if (f(el)) { + ret.push(el); + } + }); + return ret; +} +// length :: [a] -> Num +function length2(ar) { + return ar.length; +} +// curry1 :: ((a,b)->c) -> (a->(b->c)) +function curry1(f) { + return function (ay) { + return function (by) { + return f(ay, by); + }; + }; +} +var cfilter = curry1(filter); +var filterer = cfilter(strBool); +var expectFilterer = filterer; +var filtered = filterer(["hello"]); +var expectFiltered = filtered; +// compose :: (b->c) -> (a->b) -> (a->c) +// length :: [a] -> Num +// cfilter :: {} -> {} -> [{}] +// pred :: a -> Bool +// cfilter(pred) :: {} -> [{}] +// length2 :: [a] -> Num +// countWhere :: (a -> Bool) -> [a] -> Num +function countWhere_1(pred) { + return compose(length2, cfilter(pred)); +} +function countWhere_2(pred) { + var where = cfilter(pred); + return compose(length2, where); +} diff --git a/tests/baselines/reference/genericTypeParameterEquivalence2strict.symbols b/tests/baselines/reference/genericTypeParameterEquivalence2strict.symbols new file mode 100644 index 0000000000000..4157cf654017a --- /dev/null +++ b/tests/baselines/reference/genericTypeParameterEquivalence2strict.symbols @@ -0,0 +1,215 @@ +=== tests/cases/compiler/genericTypeParameterEquivalence2strict.ts === +// compose :: (b->c) -> (a->b) -> (a->c) +function compose(f: (b: B) => C, g: (a:A) => B): (a:A) => C { +>compose : Symbol(compose, Decl(genericTypeParameterEquivalence2strict.ts, 0, 0)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 1, 17)) +>B : Symbol(B, Decl(genericTypeParameterEquivalence2strict.ts, 1, 19)) +>C : Symbol(C, Decl(genericTypeParameterEquivalence2strict.ts, 1, 22)) +>f : Symbol(f, Decl(genericTypeParameterEquivalence2strict.ts, 1, 26)) +>b : Symbol(b, Decl(genericTypeParameterEquivalence2strict.ts, 1, 30)) +>B : Symbol(B, Decl(genericTypeParameterEquivalence2strict.ts, 1, 19)) +>C : Symbol(C, Decl(genericTypeParameterEquivalence2strict.ts, 1, 22)) +>g : Symbol(g, Decl(genericTypeParameterEquivalence2strict.ts, 1, 41)) +>a : Symbol(a, Decl(genericTypeParameterEquivalence2strict.ts, 1, 46)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 1, 17)) +>B : Symbol(B, Decl(genericTypeParameterEquivalence2strict.ts, 1, 19)) +>a : Symbol(a, Decl(genericTypeParameterEquivalence2strict.ts, 1, 59)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 1, 17)) +>C : Symbol(C, Decl(genericTypeParameterEquivalence2strict.ts, 1, 22)) + + return function (a:A) : C { +>a : Symbol(a, Decl(genericTypeParameterEquivalence2strict.ts, 2, 21)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 1, 17)) +>C : Symbol(C, Decl(genericTypeParameterEquivalence2strict.ts, 1, 22)) + + return f(g.apply(null, a)); +>f : Symbol(f, Decl(genericTypeParameterEquivalence2strict.ts, 1, 26)) +>g.apply : Symbol(Function.apply, Decl(lib.d.ts, --, --)) +>g : Symbol(g, Decl(genericTypeParameterEquivalence2strict.ts, 1, 41)) +>apply : Symbol(Function.apply, Decl(lib.d.ts, --, --)) +>a : Symbol(a, Decl(genericTypeParameterEquivalence2strict.ts, 2, 21)) + + }; +} + +// forEach :: [a] -> (a -> ()) -> () +function forEach(list: A[], f: (a: A, n?: number) => void ): void { +>forEach : Symbol(forEach, Decl(genericTypeParameterEquivalence2strict.ts, 5, 1)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 8, 17)) +>list : Symbol(list, Decl(genericTypeParameterEquivalence2strict.ts, 8, 20)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 8, 17)) +>f : Symbol(f, Decl(genericTypeParameterEquivalence2strict.ts, 8, 30)) +>a : Symbol(a, Decl(genericTypeParameterEquivalence2strict.ts, 8, 35)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 8, 17)) +>n : Symbol(n, Decl(genericTypeParameterEquivalence2strict.ts, 8, 40)) + + for (var i = 0; i < list.length; ++i) { +>i : Symbol(i, Decl(genericTypeParameterEquivalence2strict.ts, 9, 12)) +>i : Symbol(i, Decl(genericTypeParameterEquivalence2strict.ts, 9, 12)) +>list.length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>list : Symbol(list, Decl(genericTypeParameterEquivalence2strict.ts, 8, 20)) +>length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>i : Symbol(i, Decl(genericTypeParameterEquivalence2strict.ts, 9, 12)) + + f(list[i], i); +>f : Symbol(f, Decl(genericTypeParameterEquivalence2strict.ts, 8, 30)) +>list : Symbol(list, Decl(genericTypeParameterEquivalence2strict.ts, 8, 20)) +>i : Symbol(i, Decl(genericTypeParameterEquivalence2strict.ts, 9, 12)) +>i : Symbol(i, Decl(genericTypeParameterEquivalence2strict.ts, 9, 12)) + } +} + +// filter :: (a->bool) -> [a] -> [a] +function filter(f: (a: A) => boolean, ar: A[]): A[] { +>filter : Symbol(filter, Decl(genericTypeParameterEquivalence2strict.ts, 12, 1)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 15, 16)) +>f : Symbol(f, Decl(genericTypeParameterEquivalence2strict.ts, 15, 19)) +>a : Symbol(a, Decl(genericTypeParameterEquivalence2strict.ts, 15, 23)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 15, 16)) +>ar : Symbol(ar, Decl(genericTypeParameterEquivalence2strict.ts, 15, 40)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 15, 16)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 15, 16)) + + var ret: A[] = []; +>ret : Symbol(ret, Decl(genericTypeParameterEquivalence2strict.ts, 16, 7)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 15, 16)) + + forEach(ar, (el) => { +>forEach : Symbol(forEach, Decl(genericTypeParameterEquivalence2strict.ts, 5, 1)) +>ar : Symbol(ar, Decl(genericTypeParameterEquivalence2strict.ts, 15, 40)) +>el : Symbol(el, Decl(genericTypeParameterEquivalence2strict.ts, 17, 17)) + + if (f(el)) { +>f : Symbol(f, Decl(genericTypeParameterEquivalence2strict.ts, 15, 19)) +>el : Symbol(el, Decl(genericTypeParameterEquivalence2strict.ts, 17, 17)) + + ret.push(el); +>ret.push : Symbol(Array.push, Decl(lib.d.ts, --, --)) +>ret : Symbol(ret, Decl(genericTypeParameterEquivalence2strict.ts, 16, 7)) +>push : Symbol(Array.push, Decl(lib.d.ts, --, --)) +>el : Symbol(el, Decl(genericTypeParameterEquivalence2strict.ts, 17, 17)) + } + } ); + + return ret; +>ret : Symbol(ret, Decl(genericTypeParameterEquivalence2strict.ts, 16, 7)) +} + +// length :: [a] -> Num +function length2(ar: A[]): number { +>length2 : Symbol(length2, Decl(genericTypeParameterEquivalence2strict.ts, 24, 1)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 27, 17)) +>ar : Symbol(ar, Decl(genericTypeParameterEquivalence2strict.ts, 27, 20)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 27, 17)) + + return ar.length; +>ar.length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +>ar : Symbol(ar, Decl(genericTypeParameterEquivalence2strict.ts, 27, 20)) +>length : Symbol(Array.length, Decl(lib.d.ts, --, --)) +} + +// curry1 :: ((a,b)->c) -> (a->(b->c)) +function curry1(f: (a: A, b: B) => C): (ax: A) => (bx: B) => C { +>curry1 : Symbol(curry1, Decl(genericTypeParameterEquivalence2strict.ts, 29, 1)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 32, 16)) +>B : Symbol(B, Decl(genericTypeParameterEquivalence2strict.ts, 32, 18)) +>C : Symbol(C, Decl(genericTypeParameterEquivalence2strict.ts, 32, 21)) +>f : Symbol(f, Decl(genericTypeParameterEquivalence2strict.ts, 32, 25)) +>a : Symbol(a, Decl(genericTypeParameterEquivalence2strict.ts, 32, 29)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 32, 16)) +>b : Symbol(b, Decl(genericTypeParameterEquivalence2strict.ts, 32, 34)) +>B : Symbol(B, Decl(genericTypeParameterEquivalence2strict.ts, 32, 18)) +>C : Symbol(C, Decl(genericTypeParameterEquivalence2strict.ts, 32, 21)) +>ax : Symbol(ax, Decl(genericTypeParameterEquivalence2strict.ts, 32, 49)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 32, 16)) +>bx : Symbol(bx, Decl(genericTypeParameterEquivalence2strict.ts, 32, 60)) +>B : Symbol(B, Decl(genericTypeParameterEquivalence2strict.ts, 32, 18)) +>C : Symbol(C, Decl(genericTypeParameterEquivalence2strict.ts, 32, 21)) + + return function (ay: A) { +>ay : Symbol(ay, Decl(genericTypeParameterEquivalence2strict.ts, 33, 21)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 32, 16)) + + return function (by: B) { +>by : Symbol(by, Decl(genericTypeParameterEquivalence2strict.ts, 34, 25)) +>B : Symbol(B, Decl(genericTypeParameterEquivalence2strict.ts, 32, 18)) + + return f(ay, by); +>f : Symbol(f, Decl(genericTypeParameterEquivalence2strict.ts, 32, 25)) +>ay : Symbol(ay, Decl(genericTypeParameterEquivalence2strict.ts, 33, 21)) +>by : Symbol(by, Decl(genericTypeParameterEquivalence2strict.ts, 34, 25)) + + }; + }; +} + +var cfilter = curry1(filter); +>cfilter : Symbol(cfilter, Decl(genericTypeParameterEquivalence2strict.ts, 40, 3)) +>curry1 : Symbol(curry1, Decl(genericTypeParameterEquivalence2strict.ts, 29, 1)) +>filter : Symbol(filter, Decl(genericTypeParameterEquivalence2strict.ts, 12, 1)) + +declare function strBool(str: string): boolean +>strBool : Symbol(strBool, Decl(genericTypeParameterEquivalence2strict.ts, 40, 29)) +>str : Symbol(str, Decl(genericTypeParameterEquivalence2strict.ts, 42, 25)) + +const filterer = cfilter(strBool); +>filterer : Symbol(filterer, Decl(genericTypeParameterEquivalence2strict.ts, 43, 5)) +>cfilter : Symbol(cfilter, Decl(genericTypeParameterEquivalence2strict.ts, 40, 3)) +>strBool : Symbol(strBool, Decl(genericTypeParameterEquivalence2strict.ts, 40, 29)) + +const expectFilterer: (a: string[]) => string[] = filterer; +>expectFilterer : Symbol(expectFilterer, Decl(genericTypeParameterEquivalence2strict.ts, 44, 5)) +>a : Symbol(a, Decl(genericTypeParameterEquivalence2strict.ts, 44, 23)) +>filterer : Symbol(filterer, Decl(genericTypeParameterEquivalence2strict.ts, 43, 5)) + +const filtered = filterer(["hello"]); +>filtered : Symbol(filtered, Decl(genericTypeParameterEquivalence2strict.ts, 46, 5)) +>filterer : Symbol(filterer, Decl(genericTypeParameterEquivalence2strict.ts, 43, 5)) + +const expectFiltered: string[] = filtered; +>expectFiltered : Symbol(expectFiltered, Decl(genericTypeParameterEquivalence2strict.ts, 47, 5)) +>filtered : Symbol(filtered, Decl(genericTypeParameterEquivalence2strict.ts, 46, 5)) + +// compose :: (b->c) -> (a->b) -> (a->c) +// length :: [a] -> Num +// cfilter :: {} -> {} -> [{}] +// pred :: a -> Bool +// cfilter(pred) :: {} -> [{}] +// length2 :: [a] -> Num +// countWhere :: (a -> Bool) -> [a] -> Num + +function countWhere_1(pred: (a: A) => boolean): (a: A[]) => number { +>countWhere_1 : Symbol(countWhere_1, Decl(genericTypeParameterEquivalence2strict.ts, 47, 42)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 57, 22)) +>pred : Symbol(pred, Decl(genericTypeParameterEquivalence2strict.ts, 57, 25)) +>a : Symbol(a, Decl(genericTypeParameterEquivalence2strict.ts, 57, 32)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 57, 22)) +>a : Symbol(a, Decl(genericTypeParameterEquivalence2strict.ts, 57, 52)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 57, 22)) + + return compose(length2, cfilter(pred)); +>compose : Symbol(compose, Decl(genericTypeParameterEquivalence2strict.ts, 0, 0)) +>length2 : Symbol(length2, Decl(genericTypeParameterEquivalence2strict.ts, 24, 1)) +>cfilter : Symbol(cfilter, Decl(genericTypeParameterEquivalence2strict.ts, 40, 3)) +>pred : Symbol(pred, Decl(genericTypeParameterEquivalence2strict.ts, 57, 25)) +} + +function countWhere_2(pred: (a: A) => boolean): (a: A[]) => number { +>countWhere_2 : Symbol(countWhere_2, Decl(genericTypeParameterEquivalence2strict.ts, 59, 1)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 61, 22)) +>pred : Symbol(pred, Decl(genericTypeParameterEquivalence2strict.ts, 61, 25)) +>a : Symbol(a, Decl(genericTypeParameterEquivalence2strict.ts, 61, 32)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 61, 22)) +>a : Symbol(a, Decl(genericTypeParameterEquivalence2strict.ts, 61, 52)) +>A : Symbol(A, Decl(genericTypeParameterEquivalence2strict.ts, 61, 22)) + + var where = cfilter(pred); +>where : Symbol(where, Decl(genericTypeParameterEquivalence2strict.ts, 62, 7)) +>cfilter : Symbol(cfilter, Decl(genericTypeParameterEquivalence2strict.ts, 40, 3)) +>pred : Symbol(pred, Decl(genericTypeParameterEquivalence2strict.ts, 61, 25)) + + return compose(length2, where); +>compose : Symbol(compose, Decl(genericTypeParameterEquivalence2strict.ts, 0, 0)) +>length2 : Symbol(length2, Decl(genericTypeParameterEquivalence2strict.ts, 24, 1)) +>where : Symbol(where, Decl(genericTypeParameterEquivalence2strict.ts, 62, 7)) +} diff --git a/tests/baselines/reference/genericTypeParameterEquivalence2strict.types b/tests/baselines/reference/genericTypeParameterEquivalence2strict.types new file mode 100644 index 0000000000000..6109caa3227c3 --- /dev/null +++ b/tests/baselines/reference/genericTypeParameterEquivalence2strict.types @@ -0,0 +1,241 @@ +=== tests/cases/compiler/genericTypeParameterEquivalence2strict.ts === +// compose :: (b->c) -> (a->b) -> (a->c) +function compose(f: (b: B) => C, g: (a:A) => B): (a:A) => C { +>compose : (f: (b: B) => C, g: (a: A) => B) => (a: A) => C +>A : A +>B : B +>C : C +>f : (b: B) => C +>b : B +>B : B +>C : C +>g : (a: A) => B +>a : A +>A : A +>B : B +>a : A +>A : A +>C : C + + return function (a:A) : C { +>function (a:A) : C { return f(g.apply(null, a)); } : (a: A) => C +>a : A +>A : A +>C : C + + return f(g.apply(null, a)); +>f(g.apply(null, a)) : C +>f : (b: B) => C +>g.apply(null, a) : any +>g.apply : (this: Function, thisArg: any, argArray?: any) => any +>g : (a: A) => B +>apply : (this: Function, thisArg: any, argArray?: any) => any +>null : null +>a : A + + }; +} + +// forEach :: [a] -> (a -> ()) -> () +function forEach(list: A[], f: (a: A, n?: number) => void ): void { +>forEach : (list: A[], f: (a: A, n?: number | undefined) => void) => void +>A : A +>list : A[] +>A : A +>f : (a: A, n?: number | undefined) => void +>a : A +>A : A +>n : number | undefined + + for (var i = 0; i < list.length; ++i) { +>i : number +>0 : 0 +>i < list.length : boolean +>i : number +>list.length : number +>list : A[] +>length : number +>++i : number +>i : number + + f(list[i], i); +>f(list[i], i) : void +>f : (a: A, n?: number | undefined) => void +>list[i] : A +>list : A[] +>i : number +>i : number + } +} + +// filter :: (a->bool) -> [a] -> [a] +function filter(f: (a: A) => boolean, ar: A[]): A[] { +>filter : (f: (a: A) => boolean, ar: A[]) => A[] +>A : A +>f : (a: A) => boolean +>a : A +>A : A +>ar : A[] +>A : A +>A : A + + var ret: A[] = []; +>ret : A[] +>A : A +>[] : never[] + + forEach(ar, (el) => { +>forEach(ar, (el) => { if (f(el)) { ret.push(el); } } ) : void +>forEach : (list: A[], f: (a: A, n?: number | undefined) => void) => void +>ar : A[] +>(el) => { if (f(el)) { ret.push(el); } } : (el: A) => void +>el : A + + if (f(el)) { +>f(el) : boolean +>f : (a: A) => boolean +>el : A + + ret.push(el); +>ret.push(el) : number +>ret.push : (...items: A[]) => number +>ret : A[] +>push : (...items: A[]) => number +>el : A + } + } ); + + return ret; +>ret : A[] +} + +// length :: [a] -> Num +function length2(ar: A[]): number { +>length2 : (ar: A[]) => number +>A : A +>ar : A[] +>A : A + + return ar.length; +>ar.length : number +>ar : A[] +>length : number +} + +// curry1 :: ((a,b)->c) -> (a->(b->c)) +function curry1(f: (a: A, b: B) => C): (ax: A) => (bx: B) => C { +>curry1 : (f: (a: A, b: B) => C) => (ax: A) => (bx: B) => C +>A : A +>B : B +>C : C +>f : (a: A, b: B) => C +>a : A +>A : A +>b : B +>B : B +>C : C +>ax : A +>A : A +>bx : B +>B : B +>C : C + + return function (ay: A) { +>function (ay: A) { return function (by: B) { return f(ay, by); }; } : (ay: A) => (by: B) => C +>ay : A +>A : A + + return function (by: B) { +>function (by: B) { return f(ay, by); } : (by: B) => C +>by : B +>B : B + + return f(ay, by); +>f(ay, by) : C +>f : (a: A, b: B) => C +>ay : A +>by : B + + }; + }; +} + +var cfilter = curry1(filter); +>cfilter : any +>curry1(filter) : any +>curry1 : (f: (a: A, b: B) => C) => (ax: A) => (bx: B) => C +>filter : (f: (a: A) => boolean, ar: A[]) => A[] + +declare function strBool(str: string): boolean +>strBool : (str: string) => boolean +>str : string + +const filterer = cfilter(strBool); +>filterer : any +>cfilter(strBool) : any +>cfilter : any +>strBool : (str: string) => boolean + +const expectFilterer: (a: string[]) => string[] = filterer; +>expectFilterer : (a: string[]) => string[] +>a : string[] +>filterer : any + +const filtered = filterer(["hello"]); +>filtered : any +>filterer(["hello"]) : any +>filterer : any +>["hello"] : string[] +>"hello" : "hello" + +const expectFiltered: string[] = filtered; +>expectFiltered : string[] +>filtered : any + +// compose :: (b->c) -> (a->b) -> (a->c) +// length :: [a] -> Num +// cfilter :: {} -> {} -> [{}] +// pred :: a -> Bool +// cfilter(pred) :: {} -> [{}] +// length2 :: [a] -> Num +// countWhere :: (a -> Bool) -> [a] -> Num + +function countWhere_1(pred: (a: A) => boolean): (a: A[]) => number { +>countWhere_1 : (pred: (a: A) => boolean) => (a: A[]) => number +>A : A +>pred : (a: A) => boolean +>a : A +>A : A +>a : A[] +>A : A + + return compose(length2, cfilter(pred)); +>compose(length2, cfilter(pred)) : any +>compose : (f: (b: B) => C, g: (a: A) => B) => (a: A) => C +>length2 : (ar: A[]) => number +>cfilter(pred) : any +>cfilter : any +>pred : (a: A) => boolean +} + +function countWhere_2(pred: (a: A) => boolean): (a: A[]) => number { +>countWhere_2 : (pred: (a: A) => boolean) => (a: A[]) => number +>A : A +>pred : (a: A) => boolean +>a : A +>A : A +>a : A[] +>A : A + + var where = cfilter(pred); +>where : any +>cfilter(pred) : any +>cfilter : any +>pred : (a: A) => boolean + + return compose(length2, where); +>compose(length2, where) : any +>compose : (f: (b: B) => C, g: (a: A) => B) => (a: A) => C +>length2 : (ar: A[]) => number +>where : any +} diff --git a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.errors.txt b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.errors.txt new file mode 100644 index 0000000000000..e8eda2caa3955 --- /dev/null +++ b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.errors.txt @@ -0,0 +1,68 @@ +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions.ts(14,5): error TS2322: Type '(b: {}, a: {}) => [{}, {}]' is not assignable to type '(y: U, x: T) => [T, U]'. + Type '[{}, {}]' is not assignable to type '[T, U]'. + Type '{}' is not assignable to type 'T'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions.ts(17,7): error TS2322: Type '[{}, {}]' is not assignable to type '[number, string]'. + Type '{}' is not assignable to type 'number'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions.ts(29,7): error TS2322: Type '(x: {}) => { value: {}[]; }' is not assignable to type '(u: U) => { value: U[]; }'. + Type '{ value: {}[]; }' is not assignable to type '{ value: U[]; }'. + Types of property 'value' are incompatible. + Type '{}[]' is not assignable to type 'U[]'. + Type '{}' is not assignable to type 'U'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions.ts(33,7): error TS2322: Type '{ value: {}[]; }' is not assignable to type '{ value: string[]; }'. + Types of property 'value' are incompatible. + Type '{}[]' is not assignable to type 'string[]'. + Type '{}' is not assignable to type 'string'. + + +==== tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions.ts (4 errors) ==== + export {} + + + // example from https://github.com/Microsoft/TypeScript/issues/9366 + + function flip(f: (a: a, b: b) => c): (b: b, a: a) => c { + return (b: b, a: a) => f(a, b); + } + function zip(x: T, y: U): [T, U] { + return [x, y]; + } + + const flipped = flip(zip); + var expected: (y: U, x: T) => [T, U] = flipped; + ~~~~~~~~ +!!! error TS2322: Type '(b: {}, a: {}) => [{}, {}]' is not assignable to type '(y: U, x: T) => [T, U]'. +!!! error TS2322: Type '[{}, {}]' is not assignable to type '[T, U]'. +!!! error TS2322: Type '{}' is not assignable to type 'T'. + + const actualCallResult = flipped("test", 1234) + const expectedResult: [number, string] = actualCallResult; + ~~~~~~~~~~~~~~ +!!! error TS2322: Type '[{}, {}]' is not assignable to type '[number, string]'. +!!! error TS2322: Type '{}' is not assignable to type 'number'. + + + + + // from https://github.com/Microsoft/TypeScript/issues/16414 + + declare function compose(f: (x: A) => B, g: (y: B) => C): (x: A) => C; + declare function box(x: T): { value: T }; + declare function list(x: U): U[]; + + const composed = compose(list, box); + const expectedComposed: (u: U) => { value: U[] } = composed; + ~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '(x: {}) => { value: {}[]; }' is not assignable to type '(u: U) => { value: U[]; }'. +!!! error TS2322: Type '{ value: {}[]; }' is not assignable to type '{ value: U[]; }'. +!!! error TS2322: Types of property 'value' are incompatible. +!!! error TS2322: Type '{}[]' is not assignable to type 'U[]'. +!!! error TS2322: Type '{}' is not assignable to type 'U'. + + + const callComposed = composed("test"); + const expectedCallComposed: { value: string[] } = callComposed; + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ value: {}[]; }' is not assignable to type '{ value: string[]; }'. +!!! error TS2322: Types of property 'value' are incompatible. +!!! error TS2322: Type '{}[]' is not assignable to type 'string[]'. +!!! error TS2322: Type '{}' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.js b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.js new file mode 100644 index 0000000000000..0adfce8883372 --- /dev/null +++ b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.js @@ -0,0 +1,53 @@ +//// [inferringGenericFunctionsFromGenericFunctions.ts] +export {} + + +// example from https://github.com/Microsoft/TypeScript/issues/9366 + +function flip(f: (a: a, b: b) => c): (b: b, a: a) => c { + return (b: b, a: a) => f(a, b); +} +function zip(x: T, y: U): [T, U] { + return [x, y]; +} + +const flipped = flip(zip); +var expected: (y: U, x: T) => [T, U] = flipped; + +const actualCallResult = flipped("test", 1234) +const expectedResult: [number, string] = actualCallResult; + + + + +// from https://github.com/Microsoft/TypeScript/issues/16414 + +declare function compose(f: (x: A) => B, g: (y: B) => C): (x: A) => C; +declare function box(x: T): { value: T }; +declare function list(x: U): U[]; + +const composed = compose(list, box); +const expectedComposed: (u: U) => { value: U[] } = composed; + + +const callComposed = composed("test"); +const expectedCallComposed: { value: string[] } = callComposed; + +//// [inferringGenericFunctionsFromGenericFunctions.js] +"use strict"; +exports.__esModule = true; +// example from https://github.com/Microsoft/TypeScript/issues/9366 +function flip(f) { + return function (b, a) { return f(a, b); }; +} +function zip(x, y) { + return [x, y]; +} +var flipped = flip(zip); +var expected = flipped; +var actualCallResult = flipped("test", 1234); +var expectedResult = actualCallResult; +var composed = compose(list, box); +var expectedComposed = composed; +var callComposed = composed("test"); +var expectedCallComposed = callComposed; diff --git a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.symbols b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.symbols new file mode 100644 index 0000000000000..5f5429f06148c --- /dev/null +++ b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.symbols @@ -0,0 +1,135 @@ +=== tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions.ts === +export {} + + +// example from https://github.com/Microsoft/TypeScript/issues/9366 + +function flip(f: (a: a, b: b) => c): (b: b, a: a) => c { +>flip : Symbol(flip, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 0, 9)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 5, 14)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 5, 16)) +>c : Symbol(c, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 5, 19)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 5, 23)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 5, 27)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 5, 14)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 5, 32)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 5, 16)) +>c : Symbol(c, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 5, 19)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 5, 47)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 5, 16)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 5, 52)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 5, 14)) +>c : Symbol(c, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 5, 19)) + + return (b: b, a: a) => f(a, b); +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 6, 12)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 5, 16)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 6, 17)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 5, 14)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 5, 23)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 6, 17)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 6, 12)) +} +function zip(x: T, y: U): [T, U] { +>zip : Symbol(zip, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 7, 1)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 8, 13)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 8, 15)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 8, 19)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 8, 13)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 8, 24)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 8, 15)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 8, 13)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 8, 15)) + + return [x, y]; +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 8, 19)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 8, 24)) +} + +const flipped = flip(zip); +>flipped : Symbol(flipped, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 12, 5)) +>flip : Symbol(flip, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 0, 9)) +>zip : Symbol(zip, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 7, 1)) + +var expected: (y: U, x: T) => [T, U] = flipped; +>expected : Symbol(expected, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 13, 3)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 13, 15)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 13, 17)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 13, 21)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 13, 17)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 13, 26)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 13, 15)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 13, 15)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 13, 17)) +>flipped : Symbol(flipped, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 12, 5)) + +const actualCallResult = flipped("test", 1234) +>actualCallResult : Symbol(actualCallResult, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 15, 5)) +>flipped : Symbol(flipped, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 12, 5)) + +const expectedResult: [number, string] = actualCallResult; +>expectedResult : Symbol(expectedResult, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 16, 5)) +>actualCallResult : Symbol(actualCallResult, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 15, 5)) + + + + +// from https://github.com/Microsoft/TypeScript/issues/16414 + +declare function compose(f: (x: A) => B, g: (y: B) => C): (x: A) => C; +>compose : Symbol(compose, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 16, 58)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 23, 25)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 23, 27)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 23, 30)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 23, 34)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 23, 38)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 23, 25)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 23, 27)) +>g : Symbol(g, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 23, 49)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 23, 54)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 23, 27)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 23, 30)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 23, 68)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 23, 25)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 23, 30)) + +declare function box(x: T): { value: T }; +>box : Symbol(box, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 23, 79)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 24, 21)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 24, 24)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 24, 21)) +>value : Symbol(value, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 24, 32)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 24, 21)) + +declare function list(x: U): U[]; +>list : Symbol(list, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 24, 44)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 25, 22)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 25, 25)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 25, 22)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 25, 22)) + +const composed = compose(list, box); +>composed : Symbol(composed, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 27, 5)) +>compose : Symbol(compose, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 16, 58)) +>list : Symbol(list, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 24, 44)) +>box : Symbol(box, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 23, 79)) + +const expectedComposed: (u: U) => { value: U[] } = composed; +>expectedComposed : Symbol(expectedComposed, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 28, 5)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 28, 25)) +>u : Symbol(u, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 28, 28)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 28, 25)) +>value : Symbol(value, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 28, 38)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 28, 25)) +>composed : Symbol(composed, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 27, 5)) + + +const callComposed = composed("test"); +>callComposed : Symbol(callComposed, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 31, 5)) +>composed : Symbol(composed, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 27, 5)) + +const expectedCallComposed: { value: string[] } = callComposed; +>expectedCallComposed : Symbol(expectedCallComposed, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 32, 5)) +>value : Symbol(value, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 32, 29)) +>callComposed : Symbol(callComposed, Decl(inferringGenericFunctionsFromGenericFunctions.ts, 31, 5)) + diff --git a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.types b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.types new file mode 100644 index 0000000000000..e40bc0caec38b --- /dev/null +++ b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.types @@ -0,0 +1,145 @@ +=== tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions.ts === +export {} + + +// example from https://github.com/Microsoft/TypeScript/issues/9366 + +function flip(f: (a: a, b: b) => c): (b: b, a: a) => c { +>flip : (f: (a: a, b: b) => c) => (b: b, a: a) => c +>a : a +>b : b +>c : c +>f : (a: a, b: b) => c +>a : a +>a : a +>b : b +>b : b +>c : c +>b : b +>b : b +>a : a +>a : a +>c : c + + return (b: b, a: a) => f(a, b); +>(b: b, a: a) => f(a, b) : (b: b, a: a) => c +>b : b +>b : b +>a : a +>a : a +>f(a, b) : c +>f : (a: a, b: b) => c +>a : a +>b : b +} +function zip(x: T, y: U): [T, U] { +>zip : (x: T, y: U) => [T, U] +>T : T +>U : U +>x : T +>T : T +>y : U +>U : U +>T : T +>U : U + + return [x, y]; +>[x, y] : [T, U] +>x : T +>y : U +} + +const flipped = flip(zip); +>flipped : (b: {}, a: {}) => [{}, {}] +>flip(zip) : (b: {}, a: {}) => [{}, {}] +>flip : (f: (a: a, b: b) => c) => (b: b, a: a) => c +>zip : (x: T, y: U) => [T, U] + +var expected: (y: U, x: T) => [T, U] = flipped; +>expected : (y: U, x: T) => [T, U] +>T : T +>U : U +>y : U +>U : U +>x : T +>T : T +>T : T +>U : U +>flipped : (b: {}, a: {}) => [{}, {}] + +const actualCallResult = flipped("test", 1234) +>actualCallResult : [{}, {}] +>flipped("test", 1234) : [{}, {}] +>flipped : (b: {}, a: {}) => [{}, {}] +>"test" : "test" +>1234 : 1234 + +const expectedResult: [number, string] = actualCallResult; +>expectedResult : [number, string] +>actualCallResult : [{}, {}] + + + + +// from https://github.com/Microsoft/TypeScript/issues/16414 + +declare function compose(f: (x: A) => B, g: (y: B) => C): (x: A) => C; +>compose : (f: (x: A) => B, g: (y: B) => C) => (x: A) => C +>A : A +>B : B +>C : C +>f : (x: A) => B +>x : A +>A : A +>B : B +>g : (y: B) => C +>y : B +>B : B +>C : C +>x : A +>A : A +>C : C + +declare function box(x: T): { value: T }; +>box : (x: T) => { value: T; } +>T : T +>x : T +>T : T +>value : T +>T : T + +declare function list(x: U): U[]; +>list : (x: U) => U[] +>U : U +>x : U +>U : U +>U : U + +const composed = compose(list, box); +>composed : (x: {}) => { value: {}[]; } +>compose(list, box) : (x: {}) => { value: {}[]; } +>compose : (f: (x: A) => B, g: (y: B) => C) => (x: A) => C +>list : (x: U) => U[] +>box : (x: T) => { value: T; } + +const expectedComposed: (u: U) => { value: U[] } = composed; +>expectedComposed : (u: U) => { value: U[]; } +>U : U +>u : U +>U : U +>value : U[] +>U : U +>composed : (x: {}) => { value: {}[]; } + + +const callComposed = composed("test"); +>callComposed : { value: {}[]; } +>composed("test") : { value: {}[]; } +>composed : (x: {}) => { value: {}[]; } +>"test" : "test" + +const expectedCallComposed: { value: string[] } = callComposed; +>expectedCallComposed : { value: string[]; } +>value : string[] +>callComposed : { value: {}[]; } + diff --git a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.errors.txt b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.errors.txt new file mode 100644 index 0000000000000..5122bdc849b18 --- /dev/null +++ b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.errors.txt @@ -0,0 +1,627 @@ +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(21,32): error TS2345: Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => Date'. + Type 'string' is not assignable to type 'Date'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(22,32): error TS2345: Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => Date'. + Type 'string' is not assignable to type 'Date'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(29,7): error TS2345: Argument of type '(x: A, l: List, y: A) => A' is not assignable to parameter of type '(l: List<{}>, x: {}, y: {}) => {}'. + Types of parameters 'l' and 'x' are incompatible. + Type '{}' is not assignable to type 'List<{}>'. + Type '{}' is not assignable to type '{ kind: "cons"; val: {}; rest: List<{}>; }'. + Property 'kind' is missing in type '{}'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(37,11): error TS2345: Argument of type '(x: T, y: U) => U' is not assignable to parameter of type '(x: string, y: number) => string'. + Types of parameters 'y' and 'y' are incompatible. + Type 'number' is not assignable to type 'string'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(38,12): error TS2345: Argument of type '(x: T, y: U) => U' is not assignable to parameter of type '(x: string, y: number) => string'. + Types of parameters 'y' and 'y' are incompatible. + Type 'number' is not assignable to type 'string'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(39,26): error TS2345: Argument of type '(x: T, y: U) => U' is not assignable to parameter of type '(x: string, y: number) => string | number'. + Types of parameters 'y' and 'y' are incompatible. + Type 'number' is not assignable to type 'string'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(41,12): error TS2345: Argument of type '(x: T, y: U, z: V) => V' is not assignable to parameter of type '(x: string, y: number, z: {}) => {}'. + Types of parameters 'y' and 'y' are incompatible. + Type 'number' is not assignable to type 'string'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(42,27): error TS2345: Argument of type '(x: T, y: U, z: V) => V' is not assignable to parameter of type '(x: string, y: number, z: string | number) => string | number'. + Types of parameters 'y' and 'y' are incompatible. + Type 'number' is not assignable to type 'string'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(43,6): error TS2345: Argument of type '(x: T, y: U) => U' is not assignable to parameter of type '(x: 1, y: number) => 1'. + Types of parameters 'y' and 'y' are incompatible. + Type 'number' is not assignable to type '1'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(45,17): error TS2345: Argument of type '(x: N) => N' is not assignable to parameter of type '(x: string) => string'. + Types of parameters 'x' and 'x' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(48,8): error TS2345: Argument of type '(x: T, y: U) => U' is not assignable to parameter of type '(x: number, xs: List) => number'. + Types of parameters 'y' and 'xs' are incompatible. + Type 'List' is not assignable to type 'number'. + Type '{ kind: "nil"; }' is not assignable to type 'number'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(67,9): error TS2322: Type 'C | undefined' is not assignable to type 'C'. + Type 'undefined' is not assignable to type 'C'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(99,13): error TS2345: Argument of type '(b: B) => A' is not assignable to parameter of type '(x: B) => B'. + Type 'A' is not assignable to type 'B'. + Property 'y' is missing in type 'A'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(104,5): error TS2345: Argument of type '(x: number) => number' is not assignable to parameter of type '(x: number) => 4'. + Type 'number' is not assignable to type '4'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(109,7): error TS2345: Argument of type '({ a }: { a: any; }) => any' is not assignable to parameter of type '(x: {}) => string'. + Types of parameters '__0' and 'x' are incompatible. + Type '{}' is not assignable to type '{ a: any; }'. + Property 'a' is missing in type '{}'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(110,7): error TS2345: Argument of type '([b, c]: [any, any]) => string' is not assignable to parameter of type '(x: {}) => string'. + Types of parameters '__0' and 'x' are incompatible. + Type '{}' is not assignable to type '[any, any]'. + Property '0' is missing in type '{}'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(111,7): error TS2345: Argument of type '({ d: [e, f] }: { d: [any, any]; }) => string' is not assignable to parameter of type '(x: {}) => string'. + Types of parameters '__0' and 'x' are incompatible. + Type '{}' is not assignable to type '{ d: [any, any]; }'. + Property 'd' is missing in type '{}'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(112,7): error TS2345: Argument of type '([{ g }, { h }]: [{ g: any; }, { h: any; }]) => string' is not assignable to parameter of type '(x: {}) => string'. + Types of parameters '__0' and 'x' are incompatible. + Type '{}' is not assignable to type '[{ g: any; }, { h: any; }]'. + Property '0' is missing in type '{}'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(113,7): error TS2345: Argument of type '({ a, b }: { a: any; b?: number; }) => any' is not assignable to parameter of type '(x: {}) => string'. + Types of parameters '__0' and 'x' are incompatible. + Type '{}' is not assignable to type '{ a: any; b?: number; }'. + Property 'a' is missing in type '{}'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(120,24): error TS2345: Argument of type '(x: T, y: U) => U' is not assignable to parameter of type '(x: number, y: string) => number'. + Types of parameters 'y' and 'y' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(132,12): error TS2345: Argument of type '(x: N) => N' is not assignable to parameter of type '(x: string) => string'. + Types of parameters 'x' and 'x' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(133,11): error TS2345: Argument of type '(x: N) => N' is not assignable to parameter of type '(x: string) => string'. + Types of parameters 'x' and 'x' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(141,7): error TS2322: Type '[{}, {}]' is not assignable to type '[number, string]'. + Type '{}' is not assignable to type 'number'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(142,7): error TS2322: Type '{ x: number; y: {}; }' is not assignable to type '{ x: number; y: string; }'. + Types of property 'y' are incompatible. + Type '{}' is not assignable to type 'string'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(147,7): error TS2322: Type '[{}, {}]' is not assignable to type '[number, string]'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(148,7): error TS2322: Type '[{}, {}]' is not assignable to type '[number, string]'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(152,5): error TS2564: Property 'payload' has no initializer and is not definitely assigned in the constructor. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(166,5): error TS2564: Property 'test' has no initializer and is not definitely assigned in the constructor. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(170,17): error TS2345: Argument of type 'true' is not assignable to parameter of type '{ a: string; b: number; }'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(209,5): error TS2322: Type '(n: T) => string' is not assignable to type '(n: T) => T'. + Type 'string' is not assignable to type 'T'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(225,9): error TS2345: Argument of type 'new (x: T) => number' is not assignable to parameter of type '{ new (x: 1): string; new (x: 1, y?: 1 | undefined): string; }'. + Type 'number' is not assignable to type 'string'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(229,9): error TS2345: Argument of type 'new (x: T) => T' is not assignable to parameter of type 'new (x: 1) => string'. + Type '1' is not assignable to type 'string'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(231,9): error TS2345: Argument of type 'new (x: T) => number' is not assignable to parameter of type 'new (x: 1) => string'. + Type 'number' is not assignable to type 'string'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(235,9): error TS2345: Argument of type 'new (x: T) => T' is not assignable to parameter of type 'new (x: 1, y?: 1 | undefined) => string'. + Type '1' is not assignable to type 'string'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(237,9): error TS2345: Argument of type 'new (x: T) => number' is not assignable to parameter of type 'new (x: 1, y?: 1 | undefined) => string'. + Type 'number' is not assignable to type 'string'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(261,19): error TS2345: Argument of type '4' is not assignable to parameter of type '5'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(286,8): error TS2345: Argument of type '4' is not assignable to parameter of type 'string'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(301,17): error TS2345: Argument of type '(tag: T, value: Q) => { tag: T; value: Q; }' is not assignable to parameter of type '(a: {}, b: {}) => { tag: string; value: {}; }'. + Types of parameters 'tag' and 'a' are incompatible. + Type '{}' is not assignable to type 'string'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(310,20): error TS2345: Argument of type '(x: number) => T' is not assignable to parameter of type '(b: {}) => {}'. + Types of parameters 'x' and 'b' are incompatible. + Type '{}' is not assignable to type 'number'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(359,8): error TS2345: Argument of type '(x: number, y: string | number) => void' is not assignable to parameter of type '(a: string, b: string | number) => void'. + Types of parameters 'x' and 'a' are incompatible. + Type 'string' is not assignable to type 'number'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(365,8): error TS2345: Argument of type '(y: string | number) => void' is not assignable to parameter of type '(b: number | {}) => void'. + Types of parameters 'y' and 'b' are incompatible. + Type 'number | {}' is not assignable to type 'string | number'. + Type '{}' is not assignable to type 'string | number'. + Type '{}' is not assignable to type 'number'. + + +==== tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts (41 errors) ==== + export {} + + // Borrowed from @gcnew at https://gist.github.com/gcnew/ad833bfa376e4b70fc50a780e3b2d883 + + interface Collection { + length: number; + add(x: T): void; + remove(x: T): boolean; + } + interface Combinators { + map(c: Collection, f: (x: T) => U): Collection; + map(c: Collection, f: (x: T) => any): Collection; + forEach(c: Collection, f: (x: T) => Date): void; + } + + declare var _: Combinators; + declare var c2: Collection; + + var rf1 = (x: number) => { return x.toFixed() }; + var r1a = _.map(c2, (x) => { return x.toFixed() }); + var r5 = _.forEach(c2, rf1); // Should error + ~~~ +!!! error TS2345: Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => Date'. +!!! error TS2345: Type 'string' is not assignable to type 'Date'. + var r6 = _.forEach(c2, (x) => { return x.toFixed() }); // Should error + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => Date'. +!!! error TS2345: Type 'string' is not assignable to type 'Date'. + declare const zipWith: (a: T[], b: S[], f: (x: T) => (y: S) => U) => U[]; + declare const pair: (x: T) => (y: S) => { x: T; y: S; } + const zr = zipWith([1, 2], ['a', 'b'], pair); + + declare function lego1(x: A, l: List, y: A): A; + declare function lego2(f: (l: List, x: D, y: D) => D): void; + lego2(lego1); + ~~~~~ +!!! error TS2345: Argument of type '(x: A, l: List, y: A) => A' is not assignable to parameter of type '(l: List<{}>, x: {}, y: {}) => {}'. +!!! error TS2345: Types of parameters 'l' and 'x' are incompatible. +!!! error TS2345: Type '{}' is not assignable to type 'List<{}>'. +!!! error TS2345: Type '{}' is not assignable to type '{ kind: "cons"; val: {}; rest: List<{}>; }'. +!!! error TS2345: Property 'kind' is missing in type '{}'. + + declare function bombastic(f: (x: string, y: number) => R): R; + declare function bombastic2(f: (x: string, y: number) => string): void; + declare function bombastic3(f: (x: string, y: number, z: R) => R): R; + declare function okay(f: (x: 1, y: number) => R): R; + declare function transitive(x: T, f: (x: T) => T): void; + + bombastic(id2); // Should be an error T = [string, number] + ~~~ +!!! error TS2345: Argument of type '(x: T, y: U) => U' is not assignable to parameter of type '(x: string, y: number) => string'. +!!! error TS2345: Types of parameters 'y' and 'y' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. + bombastic2(id2); // Should be an error T = [string, number] + ~~~ +!!! error TS2345: Argument of type '(x: T, y: U) => U' is not assignable to parameter of type '(x: string, y: number) => string'. +!!! error TS2345: Types of parameters 'y' and 'y' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. + bombastic(id2); // should be an error because bombastic's callback is (x: string, y: number) => R and the explicit type argument here is setting `R`, not setting T and U from id2 + ~~~ +!!! error TS2345: Argument of type '(x: T, y: U) => U' is not assignable to parameter of type '(x: string, y: number) => string | number'. +!!! error TS2345: Types of parameters 'y' and 'y' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. + declare function id3(x: T, y: U, z: V): V; + bombastic3(id3); // Should be error + ~~~ +!!! error TS2345: Argument of type '(x: T, y: U, z: V) => V' is not assignable to parameter of type '(x: string, y: number, z: {}) => {}'. +!!! error TS2345: Types of parameters 'y' and 'y' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. + bombastic3(id3); // Should be error because of reason from bombastic(id2) + ~~~ +!!! error TS2345: Argument of type '(x: T, y: U, z: V) => V' is not assignable to parameter of type '(x: string, y: number, z: string | number) => string | number'. +!!! error TS2345: Types of parameters 'y' and 'y' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type 'string'. + okay(id2); + ~~~ +!!! error TS2345: Argument of type '(x: T, y: U) => U' is not assignable to parameter of type '(x: 1, y: number) => 1'. +!!! error TS2345: Types of parameters 'y' and 'y' are incompatible. +!!! error TS2345: Type 'number' is not assignable to type '1'. + transitive(1, withNum); + transitive('1', withNum); + ~~~~~~~ +!!! error TS2345: Argument of type '(x: N) => N' is not assignable to parameter of type '(x: string) => string'. +!!! error TS2345: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + + declare function occurs(f: (x: number, xs: List) => R): R; + occurs(id2); // should be error + ~~~ +!!! error TS2345: Argument of type '(x: T, y: U) => U' is not assignable to parameter of type '(x: number, xs: List) => number'. +!!! error TS2345: Types of parameters 'y' and 'xs' are incompatible. +!!! error TS2345: Type 'List' is not assignable to type 'number'. +!!! error TS2345: Type '{ kind: "nil"; }' is not assignable to type 'number'. + + declare function f15(x: T, f: (x: T) => T): void; + declare function g15(n: number): number; + f15(5, g15); + + interface J { + [s: string]: T; + } + + declare function g1(obj: J): T; + const rg1: string = g1({ p: "" }); + + declare function forEachChild(node: Node, cbNode: (node: Node) => T | undefined, cbNodeArray?: (nodes: NodeArray) => T | undefined): T | undefined; + + class Node { + _node: any; + + forEachChild(cbNode: (node: Node) => C, cbNodeArray?: (nodes: NodeArray) => C): C { + return forEachChild(this, cbNode, cbNodeArray); + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type 'C | undefined' is not assignable to type 'C'. +!!! error TS2322: Type 'undefined' is not assignable to type 'C'. + } + } + + interface NodeBrand { _nodearray: any } + class Declaration extends Node { _declarationBrand: any; } + class ParameterDeclaration extends Declaration { _paramdecl: any; } + interface Arr { + concat(...items: T[][]): T[]; + concat(...items: (T | T[])[]): T[]; + } + interface NodeArray extends Arr, NodeBrand { } + + declare function indexOf(hay: Arr, needle: T): number; + declare const fps: NodeArray; + declare const node: Node; + + indexOf(fps, node); + + function selfRef(n: number, callback: (n: number) => T): T { + return selfRef(n, callback); + } + + class A { x: any; } + class B extends A { y: any; } + class Chain { + then(cb: (x: T) => S): Chain { + return null!; + } + } + + declare const chainB: Chain; + chainB.then(b => new A); + ~~~~~~~~~~ +!!! error TS2345: Argument of type '(b: B) => A' is not assignable to parameter of type '(x: B) => B'. +!!! error TS2345: Type 'A' is not assignable to type 'B'. +!!! error TS2345: Property 'y' is missing in type 'A'. + + + declare function f16(f: (x: number) => 4): void; + declare function g16(x: number): number; + f16(g16); + ~~~ +!!! error TS2345: Argument of type '(x: number) => number' is not assignable to parameter of type '(x: number) => 4'. +!!! error TS2345: Type 'number' is not assignable to type '4'. + + + declare function trans(f: (x: T) => string): number; + // TODO: these should all be noImplicitAny / destructuring erros + trans(({a}) => a); + ~~~~~~~~~~ +!!! error TS2345: Argument of type '({ a }: { a: any; }) => any' is not assignable to parameter of type '(x: {}) => string'. +!!! error TS2345: Types of parameters '__0' and 'x' are incompatible. +!!! error TS2345: Type '{}' is not assignable to type '{ a: any; }'. +!!! error TS2345: Property 'a' is missing in type '{}'. + trans(([b,c]) => 'foo'); + ~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '([b, c]: [any, any]) => string' is not assignable to parameter of type '(x: {}) => string'. +!!! error TS2345: Types of parameters '__0' and 'x' are incompatible. +!!! error TS2345: Type '{}' is not assignable to type '[any, any]'. +!!! error TS2345: Property '0' is missing in type '{}'. + trans(({d: [e,f]}) => 'foo'); + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '({ d: [e, f] }: { d: [any, any]; }) => string' is not assignable to parameter of type '(x: {}) => string'. +!!! error TS2345: Types of parameters '__0' and 'x' are incompatible. +!!! error TS2345: Type '{}' is not assignable to type '{ d: [any, any]; }'. +!!! error TS2345: Property 'd' is missing in type '{}'. + trans(([{g},{h}]) => 'foo'); + ~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '([{ g }, { h }]: [{ g: any; }, { h: any; }]) => string' is not assignable to parameter of type '(x: {}) => string'. +!!! error TS2345: Types of parameters '__0' and 'x' are incompatible. +!!! error TS2345: Type '{}' is not assignable to type '[{ g: any; }, { h: any; }]'. +!!! error TS2345: Property '0' is missing in type '{}'. + trans(({a, b = 10}) => a); + ~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '({ a, b }: { a: any; b?: number; }) => any' is not assignable to parameter of type '(x: {}) => string'. +!!! error TS2345: Types of parameters '__0' and 'x' are incompatible. +!!! error TS2345: Type '{}' is not assignable to type '{ a: any; b?: number; }'. +!!! error TS2345: Property 'a' is missing in type '{}'. + + declare function idCreator(f: (x: T|undefined) => T): T; + const icn: number = idCreator(_ => 5); // ZZZ + declare function bar(x: T, y: U, cb: (x: T, y: U) => V): V; + // having a second type parameter extend the first should prevent it from inferring a "string | number" union type from (x: string, y: number) => R + declare function id2(x: T, y: U): U; + var b2 = bar(1, "one", id2); // Should be error + ~~~ +!!! error TS2345: Argument of type '(x: T, y: U) => U' is not assignable to parameter of type '(x: number, y: string) => number'. +!!! error TS2345: Types of parameters 'y' and 'y' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + + + declare function id2OneTypeParam(x: T, y: T): T; + var b4 = bar(1, "one", id2OneTypeParam); // Should be number | string + + + + declare function withNum(x: N): N; + declare function withString(f: (x: S) => S): void; + declare function useString(f: (x: string) => string): void; + + withString(withNum); // Error + ~~~~~~~ +!!! error TS2345: Argument of type '(x: N) => N' is not assignable to parameter of type '(x: string) => string'. +!!! error TS2345: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + useString(withNum); // Error + ~~~~~~~ +!!! error TS2345: Argument of type '(x: N) => N' is not assignable to parameter of type '(x: string) => string'. +!!! error TS2345: Types of parameters 'x' and 'x' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + declare function f10(x: T): T; + declare function f10(x: T, y: number): T; + + const a10: string[] = ["a", "b"]; + const b10 = a10.map(f10); + + declare function botox(idX: (x: X) => X, idY: (y: Y) => Y): (x: X, y: Y) => [X, Y]; + const xyPair: [number, string] = botox(id, id)(3, 'str'); + ~~~~~~ +!!! error TS2322: Type '[{}, {}]' is not assignable to type '[number, string]'. +!!! error TS2322: Type '{}' is not assignable to type 'number'. + const testPair: { x: number, y: string } = pair(3)('str'); + ~~~~~~~~ +!!! error TS2322: Type '{ x: number; y: {}; }' is not assignable to type '{ x: number; y: string; }'. +!!! error TS2322: Types of property 'y' are incompatible. +!!! error TS2322: Type '{}' is not assignable to type 'string'. + + declare function botox2(idX: { a: (x: X) => X }, idY: { a: (y: Y) => Y }): (x: X, y: Y) => [X, Y]; + + const bottoxObj = { a: id }; + const xyPair2: [number, string] = botox2(bottoxObj, bottoxObj)(3, 'str'); // ZZZ + ~~~~~~~ +!!! error TS2322: Type '[{}, {}]' is not assignable to type '[number, string]'. + const xyPair3: [number, string] = botox2({ a: id }, { a: id })(3, 'str'); + ~~~~~~~ +!!! error TS2322: Type '[{}, {}]' is not assignable to type '[number, string]'. + + + class GenericClass { + payload: T; + ~~~~~~~ +!!! error TS2564: Property 'payload' has no initializer and is not definitely assigned in the constructor. + } + + var genericObject = new GenericClass<{ greeting: string }>(); + + function genericFunction(object: GenericClass, callback: (payload: T) => void) { + callback(object.payload); + } + + genericFunction(genericObject, ({greeting}) => { + var s = greeting.toLocaleLowerCase(); // Greeting should be of type string + }); + + class Foo{ + test: T; + ~~~~ +!!! error TS2564: Property 'test' has no initializer and is not definitely assigned in the constructor. + constructor(x: T){} + } + + var x = new Foo(true); // Should error + ~~~~ +!!! error TS2345: Argument of type 'true' is not assignable to parameter of type '{ a: string; b: number; }'. + var y = new Foo({a: "test", b: 42}); // Should be OK + var z: number = y.test.b; + + declare function withFew(values: a[], haveFew: (values: a[]) => r, haveNone: (reason: string) => r): r; + function fail(message: string) : never { throw new Error(message); } + const result: number[] = withFew([1, 2, 3], id, fail); // expected result is number[] + type List = { kind: 'nil' } + | { kind: 'cons', val: T, rest: List } + + const Nil = { kind: 'nil' as 'nil' } + + declare function cons(x: C, xs: List): List; + declare function foldr(list: List, initial: A, f: (x: V, acc: A) => A): A; + + function concat(list: List>): List { + return foldr(list, Nil as List, append); + } + + function append(xs: List, ys: List): List { + return foldr(xs, ys, cons); + } + + declare function zest(x: T): void; + zest(5); // should be number + function append2(xs: List, ys: List): List { + return foldr(xs, ys, flip(fconst)); // ZZZ + } + + function append3(xs: List, ys: List) { + return foldr(xs, ys, flip(fconst)); + } + + function append4(xs: List, ys: List) { + return foldr(xs, ys, flip(flip(cons))); + } + + const infPowa: typeof append = append3; // ZZZ + let jj = (n: T) => 'Error please?'; + let myFunc: (n: T) => T = jj; + ~~~~~~ +!!! error TS2322: Type '(n: T) => string' is not assignable to type '(n: T) => T'. +!!! error TS2322: Type 'string' is not assignable to type 'T'. + + function foo(x: T): T { return x; } + const r1 = foo(function (x: string) { return x; }); + const r2 = foo((x: string) => x); + const r3 = foo(function (x: any) { return x; }); + + + declare const cb1: { new (x: T): T }; + declare const cb2: { new(x: T): number; new(x: number): T; } + declare const cb3: { new(x: T): number; } + declare const cb4: { new(x: number): T; } + declare function foo7(x:T, cb: { new(x: T): string; new(x: T, y?: T): string }): void; + + foo7(1, cb1); // Should error (but won't error because type parameters erased when comparing more than one signature) + foo7(1, cb2); + foo7(1, cb3); + ~~~ +!!! error TS2345: Argument of type 'new (x: T) => number' is not assignable to parameter of type '{ new (x: 1): string; new (x: 1, y?: 1 | undefined): string; }'. +!!! error TS2345: Type 'number' is not assignable to type 'string'. + foo7(1, cb4); + + declare function foo8(x:T, cb: { new(x: T): string; }): void; + foo8(1, cb1); // Should error + ~~~ +!!! error TS2345: Argument of type 'new (x: T) => T' is not assignable to parameter of type 'new (x: 1) => string'. +!!! error TS2345: Type '1' is not assignable to type 'string'. + foo8(1, cb2); + foo8(1, cb3); + ~~~ +!!! error TS2345: Argument of type 'new (x: T) => number' is not assignable to parameter of type 'new (x: 1) => string'. +!!! error TS2345: Type 'number' is not assignable to type 'string'. + foo8(1, cb4); + + declare function foo9(x:T, cb: { new(x: T, y?: T): string }): void; + foo9(1, cb1); // Should error + ~~~ +!!! error TS2345: Argument of type 'new (x: T) => T' is not assignable to parameter of type 'new (x: 1, y?: 1 | undefined) => string'. +!!! error TS2345: Type '1' is not assignable to type 'string'. + foo9(1, cb2); + foo9(1, cb3); + ~~~ +!!! error TS2345: Argument of type 'new (x: T) => number' is not assignable to parameter of type 'new (x: 1, y?: 1 | undefined) => string'. +!!! error TS2345: Type 'number' is not assignable to type 'string'. + foo9(1, cb4); + + function map(items: A[], f: (x: A) => B): B[]{ + return items.map(f); + } + + var v10: number[] = map([1, 2, 3], id); // Error if not number[] + function foo3(x: T, cb: (a: T) => U, y: U) { + return cb(x); + } + + var r7 = foo3(1, (a: Z) => '', ''); // string + declare var a: { new (x: T): T; }; + function foo2(x: T, cb: new(a: T) => U) { + return new cb(x); + } + + var r4b = foo2(1, a); // number + + function wf(n: N, f: (x: 5) => N): N { + return f(n); + } + const wfr: 5 = wf(5, id); + const wfr2 = wf(4, id); // error + ~ +!!! error TS2345: Argument of type '4' is not assignable to parameter of type '5'. + declare function flip(f: (a: A, b: B) => R): (b: B, a: A) => R; + + function id(x: I): I { + return x; + } + + function fconst(x: X, y: Y): X { + return x; + } + + function addStr(x: number, y: string) { + return x + y; + } + + function tagged(tag: T, value: Q): { tag: T, value: Q } { + return { tag, value }; + } + + function fbound(tag: T, value: Q): { tag: T, value: Q } { + return { tag, value }; + } + + fbound(4, 4).tag; // 4 (better) or number + flip(fbound)(4, 4) // OK + fbound(4, "4"); // Error + ~ +!!! error TS2345: Argument of type '4' is not assignable to parameter of type 'string'. + flip(fbound)("4", 4) // Error + + function of2(one: a, two: b): [a, b] { + return [one, two]; + } + const flipped = flip(of2); + + // it was working before + const f1 = flip(addStr); // (b: string, a: number) => string + const v1 = f1("hello", 3); + const v2 = id(id)(3); // `3` + // working now + const f2 = flip(id); // (b: {}, a: T): T + const f3 = flip(fconst); // (b: Y, a: X) => X + const f4 = flip(tagged); // (b: Q, a: T) => { tag: T, value: Q } + ~~~~~~ +!!! error TS2345: Argument of type '(tag: T, value: Q) => { tag: T; value: Q; }' is not assignable to parameter of type '(a: {}, b: {}) => { tag: string; value: {}; }'. +!!! error TS2345: Types of parameters 'tag' and 'a' are incompatible. +!!! error TS2345: Type '{}' is not assignable to type 'string'. + const v3 = f3(1, "qw") // `"qw"` + const v4 = f3([], {}) // `{}` + const v5 = f4(5, "hello"); // { tag: "hello", value: number } + const v6 = f4(5, 5); // Error as expected + declare function compose(f: (b: B) => C, g: (a: A) => B): (a: A) => C; + + declare const f: (x:number) => T; + declare const g: (x:boolean) => number; + const f5 = compose(f, g) // OUCH! this gets type `(a: boolean) => T` + ~ +!!! error TS2345: Argument of type '(x: number) => T' is not assignable to parameter of type '(b: {}) => {}'. +!!! error TS2345: Types of parameters 'x' and 'b' are incompatible. +!!! error TS2345: Type '{}' is not assignable to type 'number'. + declare const g_2: (x: T) => boolean; + declare const f_2: (x: boolean) => number; + const f6 = compose(f_2, g_2) // (a: T) => number + const f7 = compose(id, x => String(x)) // (a: {}) => string + declare function h(f: (x: number) => R): R; + var z: number = h(id); + + const arr: number[] = [1, 2, 3].map(id); + + declare const val1: string | undefined; + declare function cleanse(x: T|undefined): x is T; + + cleanse(val1); + + class MyClass + { + one(c: boolean){}; + two(){}; + } + + declare const test: PickPrototype; + type PickPrototype = { + [P in K]: T['prototype'][P]; + } + + + function wrap(innerFunc: (data: T) => any) { + return (data:T) => innerFunc(data); + } + + function inner(x:number) {}; + inner(2); + + let func = wrap(inner); + func(2); + + + declare function union(f: (a: A|B|C, b: A|B|C, c: A|B|C) => void): void; + union((x: X, y: Y, z: Z) => x) + + declare function union2(f: (a: A, b: B, c: C) => void): void; + union2((x: X|Y|Z, y: X|Y|Z, z: X|Y|Z) => x); + + declare function union3(f: (a: A|string, b: A|number) => B): B; + declare function uParam31(x: X|number, y: X|string): X; + declare function uParam32(x: number, y: number|string): void; + declare function uParam33(x: string, y: number|string): void; + union3(uParam31); // error; A,X = [number, string] + union3(uParam32); // error + ~~~~~~~~ +!!! error TS2345: Argument of type '(x: number, y: string | number) => void' is not assignable to parameter of type '(a: string, b: string | number) => void'. +!!! error TS2345: Types of parameters 'x' and 'a' are incompatible. +!!! error TS2345: Type 'string' is not assignable to type 'number'. + union3(uParam33); // OK; A = string; B = void + declare function union4(f: (b: A|B) => C, a: A): C; + declare function uParam41(y: number|string): void; + declare function uParam42(y: number|X): X; + declare function uParam43(y: string|X): X; + union4(uParam41, 4); // A = number, B = string, C = void + ~~~~~~~~ +!!! error TS2345: Argument of type '(y: string | number) => void' is not assignable to parameter of type '(b: number | {}) => void'. +!!! error TS2345: Types of parameters 'y' and 'b' are incompatible. +!!! error TS2345: Type 'number | {}' is not assignable to type 'string | number'. +!!! error TS2345: Type '{}' is not assignable to type 'string | number'. +!!! error TS2345: Type '{}' is not assignable to type 'number'. + union4(uParam42, 4); // A = number, B = X, C = X + union4(uParam43, 4); // A = number, B = string, C = number \ No newline at end of file diff --git a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.js b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.js new file mode 100644 index 0000000000000..68763b1dc20f1 --- /dev/null +++ b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.js @@ -0,0 +1,622 @@ +//// [inferringGenericFunctionsFromGenericFunctions2.ts] +export {} + +// Borrowed from @gcnew at https://gist.github.com/gcnew/ad833bfa376e4b70fc50a780e3b2d883 + +interface Collection { + length: number; + add(x: T): void; + remove(x: T): boolean; +} +interface Combinators { + map(c: Collection, f: (x: T) => U): Collection; + map(c: Collection, f: (x: T) => any): Collection; + forEach(c: Collection, f: (x: T) => Date): void; +} + +declare var _: Combinators; +declare var c2: Collection; + +var rf1 = (x: number) => { return x.toFixed() }; +var r1a = _.map(c2, (x) => { return x.toFixed() }); +var r5 = _.forEach(c2, rf1); // Should error +var r6 = _.forEach(c2, (x) => { return x.toFixed() }); // Should error +declare const zipWith: (a: T[], b: S[], f: (x: T) => (y: S) => U) => U[]; +declare const pair: (x: T) => (y: S) => { x: T; y: S; } +const zr = zipWith([1, 2], ['a', 'b'], pair); + +declare function lego1(x: A, l: List, y: A): A; +declare function lego2(f: (l: List, x: D, y: D) => D): void; +lego2(lego1); + +declare function bombastic(f: (x: string, y: number) => R): R; +declare function bombastic2(f: (x: string, y: number) => string): void; +declare function bombastic3(f: (x: string, y: number, z: R) => R): R; +declare function okay(f: (x: 1, y: number) => R): R; +declare function transitive(x: T, f: (x: T) => T): void; + +bombastic(id2); // Should be an error T = [string, number] +bombastic2(id2); // Should be an error T = [string, number] +bombastic(id2); // should be an error because bombastic's callback is (x: string, y: number) => R and the explicit type argument here is setting `R`, not setting T and U from id2 +declare function id3(x: T, y: U, z: V): V; +bombastic3(id3); // Should be error +bombastic3(id3); // Should be error because of reason from bombastic(id2) +okay(id2); +transitive(1, withNum); +transitive('1', withNum); + +declare function occurs(f: (x: number, xs: List) => R): R; +occurs(id2); // should be error + +declare function f15(x: T, f: (x: T) => T): void; +declare function g15(n: number): number; +f15(5, g15); + +interface J { + [s: string]: T; +} + +declare function g1(obj: J): T; +const rg1: string = g1({ p: "" }); + +declare function forEachChild(node: Node, cbNode: (node: Node) => T | undefined, cbNodeArray?: (nodes: NodeArray) => T | undefined): T | undefined; + +class Node { + _node: any; + + forEachChild(cbNode: (node: Node) => C, cbNodeArray?: (nodes: NodeArray) => C): C { + return forEachChild(this, cbNode, cbNodeArray); + } +} + +interface NodeBrand { _nodearray: any } +class Declaration extends Node { _declarationBrand: any; } +class ParameterDeclaration extends Declaration { _paramdecl: any; } +interface Arr { + concat(...items: T[][]): T[]; + concat(...items: (T | T[])[]): T[]; +} +interface NodeArray extends Arr, NodeBrand { } + +declare function indexOf(hay: Arr, needle: T): number; +declare const fps: NodeArray; +declare const node: Node; + +indexOf(fps, node); + +function selfRef(n: number, callback: (n: number) => T): T { + return selfRef(n, callback); +} + +class A { x: any; } +class B extends A { y: any; } +class Chain { + then(cb: (x: T) => S): Chain { + return null!; + } +} + +declare const chainB: Chain; +chainB.then(b => new A); + + +declare function f16(f: (x: number) => 4): void; +declare function g16(x: number): number; +f16(g16); + + +declare function trans(f: (x: T) => string): number; +// TODO: these should all be noImplicitAny / destructuring erros +trans(({a}) => a); +trans(([b,c]) => 'foo'); +trans(({d: [e,f]}) => 'foo'); +trans(([{g},{h}]) => 'foo'); +trans(({a, b = 10}) => a); + +declare function idCreator(f: (x: T|undefined) => T): T; +const icn: number = idCreator(_ => 5); // ZZZ +declare function bar(x: T, y: U, cb: (x: T, y: U) => V): V; +// having a second type parameter extend the first should prevent it from inferring a "string | number" union type from (x: string, y: number) => R +declare function id2(x: T, y: U): U; +var b2 = bar(1, "one", id2); // Should be error + + +declare function id2OneTypeParam(x: T, y: T): T; +var b4 = bar(1, "one", id2OneTypeParam); // Should be number | string + + + +declare function withNum(x: N): N; +declare function withString(f: (x: S) => S): void; +declare function useString(f: (x: string) => string): void; + +withString(withNum); // Error +useString(withNum); // Error +declare function f10(x: T): T; +declare function f10(x: T, y: number): T; + +const a10: string[] = ["a", "b"]; +const b10 = a10.map(f10); + +declare function botox(idX: (x: X) => X, idY: (y: Y) => Y): (x: X, y: Y) => [X, Y]; +const xyPair: [number, string] = botox(id, id)(3, 'str'); +const testPair: { x: number, y: string } = pair(3)('str'); + +declare function botox2(idX: { a: (x: X) => X }, idY: { a: (y: Y) => Y }): (x: X, y: Y) => [X, Y]; + +const bottoxObj = { a: id }; +const xyPair2: [number, string] = botox2(bottoxObj, bottoxObj)(3, 'str'); // ZZZ +const xyPair3: [number, string] = botox2({ a: id }, { a: id })(3, 'str'); + + +class GenericClass { + payload: T; +} + +var genericObject = new GenericClass<{ greeting: string }>(); + +function genericFunction(object: GenericClass, callback: (payload: T) => void) { + callback(object.payload); +} + +genericFunction(genericObject, ({greeting}) => { + var s = greeting.toLocaleLowerCase(); // Greeting should be of type string +}); + +class Foo{ + test: T; + constructor(x: T){} +} + +var x = new Foo(true); // Should error +var y = new Foo({a: "test", b: 42}); // Should be OK +var z: number = y.test.b; + +declare function withFew(values: a[], haveFew: (values: a[]) => r, haveNone: (reason: string) => r): r; +function fail(message: string) : never { throw new Error(message); } +const result: number[] = withFew([1, 2, 3], id, fail); // expected result is number[] +type List = { kind: 'nil' } + | { kind: 'cons', val: T, rest: List } + +const Nil = { kind: 'nil' as 'nil' } + +declare function cons(x: C, xs: List): List; +declare function foldr(list: List, initial: A, f: (x: V, acc: A) => A): A; + +function concat(list: List>): List { + return foldr(list, Nil as List, append); +} + +function append(xs: List, ys: List): List { + return foldr(xs, ys, cons); +} + +declare function zest(x: T): void; +zest(5); // should be number +function append2(xs: List, ys: List): List { + return foldr(xs, ys, flip(fconst)); // ZZZ +} + +function append3(xs: List, ys: List) { + return foldr(xs, ys, flip(fconst)); +} + +function append4(xs: List, ys: List) { + return foldr(xs, ys, flip(flip(cons))); +} + +const infPowa: typeof append = append3; // ZZZ +let jj = (n: T) => 'Error please?'; +let myFunc: (n: T) => T = jj; + +function foo(x: T): T { return x; } +const r1 = foo(function (x: string) { return x; }); +const r2 = foo((x: string) => x); +const r3 = foo(function (x: any) { return x; }); + + +declare const cb1: { new (x: T): T }; +declare const cb2: { new(x: T): number; new(x: number): T; } +declare const cb3: { new(x: T): number; } +declare const cb4: { new(x: number): T; } +declare function foo7(x:T, cb: { new(x: T): string; new(x: T, y?: T): string }): void; + +foo7(1, cb1); // Should error (but won't error because type parameters erased when comparing more than one signature) +foo7(1, cb2); +foo7(1, cb3); +foo7(1, cb4); + +declare function foo8(x:T, cb: { new(x: T): string; }): void; +foo8(1, cb1); // Should error +foo8(1, cb2); +foo8(1, cb3); +foo8(1, cb4); + +declare function foo9(x:T, cb: { new(x: T, y?: T): string }): void; +foo9(1, cb1); // Should error +foo9(1, cb2); +foo9(1, cb3); +foo9(1, cb4); + +function map(items: A[], f: (x: A) => B): B[]{ + return items.map(f); +} + +var v10: number[] = map([1, 2, 3], id); // Error if not number[] +function foo3(x: T, cb: (a: T) => U, y: U) { + return cb(x); +} + +var r7 = foo3(1, (a: Z) => '', ''); // string +declare var a: { new (x: T): T; }; +function foo2(x: T, cb: new(a: T) => U) { + return new cb(x); +} + +var r4b = foo2(1, a); // number + +function wf(n: N, f: (x: 5) => N): N { + return f(n); +} +const wfr: 5 = wf(5, id); +const wfr2 = wf(4, id); // error +declare function flip(f: (a: A, b: B) => R): (b: B, a: A) => R; + +function id(x: I): I { + return x; +} + +function fconst(x: X, y: Y): X { + return x; +} + +function addStr(x: number, y: string) { + return x + y; +} + +function tagged(tag: T, value: Q): { tag: T, value: Q } { + return { tag, value }; +} + +function fbound(tag: T, value: Q): { tag: T, value: Q } { + return { tag, value }; +} + +fbound(4, 4).tag; // 4 (better) or number +flip(fbound)(4, 4) // OK +fbound(4, "4"); // Error +flip(fbound)("4", 4) // Error + +function of2(one: a, two: b): [a, b] { + return [one, two]; +} +const flipped = flip(of2); + +// it was working before +const f1 = flip(addStr); // (b: string, a: number) => string +const v1 = f1("hello", 3); +const v2 = id(id)(3); // `3` +// working now +const f2 = flip(id); // (b: {}, a: T): T +const f3 = flip(fconst); // (b: Y, a: X) => X +const f4 = flip(tagged); // (b: Q, a: T) => { tag: T, value: Q } +const v3 = f3(1, "qw") // `"qw"` +const v4 = f3([], {}) // `{}` +const v5 = f4(5, "hello"); // { tag: "hello", value: number } +const v6 = f4(5, 5); // Error as expected +declare function compose(f: (b: B) => C, g: (a: A) => B): (a: A) => C; + +declare const f: (x:number) => T; +declare const g: (x:boolean) => number; +const f5 = compose(f, g) // OUCH! this gets type `(a: boolean) => T` +declare const g_2: (x: T) => boolean; +declare const f_2: (x: boolean) => number; +const f6 = compose(f_2, g_2) // (a: T) => number +const f7 = compose(id, x => String(x)) // (a: {}) => string +declare function h(f: (x: number) => R): R; +var z: number = h(id); + +const arr: number[] = [1, 2, 3].map(id); + +declare const val1: string | undefined; +declare function cleanse(x: T|undefined): x is T; + +cleanse(val1); + +class MyClass +{ + one(c: boolean){}; + two(){}; +} + +declare const test: PickPrototype; +type PickPrototype = { + [P in K]: T['prototype'][P]; +} + + +function wrap(innerFunc: (data: T) => any) { + return (data:T) => innerFunc(data); +} + +function inner(x:number) {}; +inner(2); + +let func = wrap(inner); +func(2); + + +declare function union(f: (a: A|B|C, b: A|B|C, c: A|B|C) => void): void; +union((x: X, y: Y, z: Z) => x) + +declare function union2(f: (a: A, b: B, c: C) => void): void; +union2((x: X|Y|Z, y: X|Y|Z, z: X|Y|Z) => x); + +declare function union3(f: (a: A|string, b: A|number) => B): B; +declare function uParam31(x: X|number, y: X|string): X; +declare function uParam32(x: number, y: number|string): void; +declare function uParam33(x: string, y: number|string): void; +union3(uParam31); // error; A,X = [number, string] +union3(uParam32); // error +union3(uParam33); // OK; A = string; B = void +declare function union4(f: (b: A|B) => C, a: A): C; +declare function uParam41(y: number|string): void; +declare function uParam42(y: number|X): X; +declare function uParam43(y: string|X): X; +union4(uParam41, 4); // A = number, B = string, C = void +union4(uParam42, 4); // A = number, B = X, C = X +union4(uParam43, 4); // A = number, B = string, C = number + +//// [inferringGenericFunctionsFromGenericFunctions2.js] +"use strict"; +var __extends = (this && this.__extends) || (function () { + var extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +exports.__esModule = true; +var rf1 = function (x) { return x.toFixed(); }; +var r1a = _.map(c2, function (x) { return x.toFixed(); }); +var r5 = _.forEach(c2, rf1); // Should error +var r6 = _.forEach(c2, function (x) { return x.toFixed(); }); // Should error +var zr = zipWith([1, 2], ['a', 'b'], pair); +lego2(lego1); +bombastic(id2); // Should be an error T = [string, number] +bombastic2(id2); // Should be an error T = [string, number] +bombastic(id2); // should be an error because bombastic's callback is (x: string, y: number) => R and the explicit type argument here is setting `R`, not setting T and U from id2 +bombastic3(id3); // Should be error +bombastic3(id3); // Should be error because of reason from bombastic(id2) +okay(id2); +transitive(1, withNum); +transitive('1', withNum); +occurs(id2); // should be error +f15(5, g15); +var rg1 = g1({ p: "" }); +var Node = /** @class */ (function () { + function Node() { + } + Node.prototype.forEachChild = function (cbNode, cbNodeArray) { + return forEachChild(this, cbNode, cbNodeArray); + }; + return Node; +}()); +var Declaration = /** @class */ (function (_super) { + __extends(Declaration, _super); + function Declaration() { + return _super !== null && _super.apply(this, arguments) || this; + } + return Declaration; +}(Node)); +var ParameterDeclaration = /** @class */ (function (_super) { + __extends(ParameterDeclaration, _super); + function ParameterDeclaration() { + return _super !== null && _super.apply(this, arguments) || this; + } + return ParameterDeclaration; +}(Declaration)); +indexOf(fps, node); +function selfRef(n, callback) { + return selfRef(n, callback); +} +var A = /** @class */ (function () { + function A() { + } + return A; +}()); +var B = /** @class */ (function (_super) { + __extends(B, _super); + function B() { + return _super !== null && _super.apply(this, arguments) || this; + } + return B; +}(A)); +var Chain = /** @class */ (function () { + function Chain() { + } + Chain.prototype.then = function (cb) { + return null; + }; + return Chain; +}()); +chainB.then(function (b) { return new A; }); +f16(g16); +// TODO: these should all be noImplicitAny / destructuring erros +trans(function (_a) { + var a = _a.a; + return a; +}); +trans(function (_a) { + var b = _a[0], c = _a[1]; + return 'foo'; +}); +trans(function (_a) { + var _b = _a.d, e = _b[0], f = _b[1]; + return 'foo'; +}); +trans(function (_a) { + var g = _a[0].g, h = _a[1].h; + return 'foo'; +}); +trans(function (_a) { + var a = _a.a, _b = _a.b, b = _b === void 0 ? 10 : _b; + return a; +}); +var icn = idCreator(function (_) { return 5; }); // ZZZ +var b2 = bar(1, "one", id2); // Should be error +var b4 = bar(1, "one", id2OneTypeParam); // Should be number | string +withString(withNum); // Error +useString(withNum); // Error +var a10 = ["a", "b"]; +var b10 = a10.map(f10); +var xyPair = botox(id, id)(3, 'str'); +var testPair = pair(3)('str'); +var bottoxObj = { a: id }; +var xyPair2 = botox2(bottoxObj, bottoxObj)(3, 'str'); // ZZZ +var xyPair3 = botox2({ a: id }, { a: id })(3, 'str'); +var GenericClass = /** @class */ (function () { + function GenericClass() { + } + return GenericClass; +}()); +var genericObject = new GenericClass(); +function genericFunction(object, callback) { + callback(object.payload); +} +genericFunction(genericObject, function (_a) { + var greeting = _a.greeting; + var s = greeting.toLocaleLowerCase(); // Greeting should be of type string +}); +var Foo = /** @class */ (function () { + function Foo(x) { + } + return Foo; +}()); +var x = new Foo(true); // Should error +var y = new Foo({ a: "test", b: 42 }); // Should be OK +var z = y.test.b; +function fail(message) { throw new Error(message); } +var result = withFew([1, 2, 3], id, fail); // expected result is number[] +var Nil = { kind: 'nil' }; +function concat(list) { + return foldr(list, Nil, append); +} +function append(xs, ys) { + return foldr(xs, ys, cons); +} +zest(5); // should be number +function append2(xs, ys) { + return foldr(xs, ys, flip(fconst)); // ZZZ +} +function append3(xs, ys) { + return foldr(xs, ys, flip(fconst)); +} +function append4(xs, ys) { + return foldr(xs, ys, flip(flip(cons))); +} +var infPowa = append3; // ZZZ +var jj = function (n) { return 'Error please?'; }; +var myFunc = jj; +function foo(x) { return x; } +var r1 = foo(function (x) { return x; }); +var r2 = foo(function (x) { return x; }); +var r3 = foo(function (x) { return x; }); +foo7(1, cb1); // Should error (but won't error because type parameters erased when comparing more than one signature) +foo7(1, cb2); +foo7(1, cb3); +foo7(1, cb4); +foo8(1, cb1); // Should error +foo8(1, cb2); +foo8(1, cb3); +foo8(1, cb4); +foo9(1, cb1); // Should error +foo9(1, cb2); +foo9(1, cb3); +foo9(1, cb4); +function map(items, f) { + return items.map(f); +} +var v10 = map([1, 2, 3], id); // Error if not number[] +function foo3(x, cb, y) { + return cb(x); +} +var r7 = foo3(1, function (a) { return ''; }, ''); // string +function foo2(x, cb) { + return new cb(x); +} +var r4b = foo2(1, a); // number +function wf(n, f) { + return f(n); +} +var wfr = wf(5, id); +var wfr2 = wf(4, id); // error +function id(x) { + return x; +} +function fconst(x, y) { + return x; +} +function addStr(x, y) { + return x + y; +} +function tagged(tag, value) { + return { tag: tag, value: value }; +} +function fbound(tag, value) { + return { tag: tag, value: value }; +} +fbound(4, 4).tag; // 4 (better) or number +flip(fbound)(4, 4); // OK +fbound(4, "4"); // Error +flip(fbound)("4", 4); // Error +function of2(one, two) { + return [one, two]; +} +var flipped = flip(of2); +// it was working before +var f1 = flip(addStr); // (b: string, a: number) => string +var v1 = f1("hello", 3); +var v2 = id(id)(3); // `3` +// working now +var f2 = flip(id); // (b: {}, a: T): T +var f3 = flip(fconst); // (b: Y, a: X) => X +var f4 = flip(tagged); // (b: Q, a: T) => { tag: T, value: Q } +var v3 = f3(1, "qw"); // `"qw"` +var v4 = f3([], {}); // `{}` +var v5 = f4(5, "hello"); // { tag: "hello", value: number } +var v6 = f4(5, 5); // Error as expected +var f5 = compose(f, g); // OUCH! this gets type `(a: boolean) => T` +var f6 = compose(f_2, g_2); // (a: T) => number +var f7 = compose(id, function (x) { return String(x); }); // (a: {}) => string +var z = h(id); +var arr = [1, 2, 3].map(id); +cleanse(val1); +var MyClass = /** @class */ (function () { + function MyClass() { + } + MyClass.prototype.one = function (c) { }; + ; + MyClass.prototype.two = function () { }; + ; + return MyClass; +}()); +function wrap(innerFunc) { + return function (data) { return innerFunc(data); }; +} +function inner(x) { } +; +inner(2); +var func = wrap(inner); +func(2); +union(function (x, y, z) { return x; }); +union2(function (x, y, z) { return x; }); +union3(uParam31); // error; A,X = [number, string] +union3(uParam32); // error +union3(uParam33); // OK; A = string; B = void +union4(uParam41, 4); // A = number, B = string, C = void +union4(uParam42, 4); // A = number, B = X, C = X +union4(uParam43, 4); // A = number, B = string, C = number diff --git a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.symbols b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.symbols new file mode 100644 index 0000000000000..17a01d1f8af85 --- /dev/null +++ b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.symbols @@ -0,0 +1,1706 @@ +=== tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts === +export {} + +// Borrowed from @gcnew at https://gist.github.com/gcnew/ad833bfa376e4b70fc50a780e3b2d883 + +interface Collection { +>Collection : Symbol(Collection, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 0, 9)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 4, 21)) + + length: number; +>length : Symbol(Collection.length, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 4, 25)) + + add(x: T): void; +>add : Symbol(Collection.add, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 5, 19)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 6, 8)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 4, 21)) + + remove(x: T): boolean; +>remove : Symbol(Collection.remove, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 6, 20)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 7, 11)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 4, 21)) +} +interface Combinators { +>Combinators : Symbol(Combinators, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 8, 1)) + + map(c: Collection, f: (x: T) => U): Collection; +>map : Symbol(Combinators.map, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 9, 23), Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 10, 63)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 10, 8)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 10, 10)) +>c : Symbol(c, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 10, 14)) +>Collection : Symbol(Collection, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 0, 9)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 10, 8)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 10, 31)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 10, 36)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 10, 8)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 10, 10)) +>Collection : Symbol(Collection, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 0, 9)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 10, 10)) + + map(c: Collection, f: (x: T) => any): Collection; +>map : Symbol(Combinators.map, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 9, 23), Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 10, 63)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 11, 8)) +>c : Symbol(c, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 11, 11)) +>Collection : Symbol(Collection, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 0, 9)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 11, 8)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 11, 28)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 11, 33)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 11, 8)) +>Collection : Symbol(Collection, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 0, 9)) + + forEach(c: Collection, f: (x: T) => Date): void; +>forEach : Symbol(Combinators.forEach, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 11, 64)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 12, 12)) +>c : Symbol(c, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 12, 15)) +>Collection : Symbol(Collection, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 0, 9)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 12, 12)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 12, 32)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 12, 37)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 12, 12)) +>Date : Symbol(Date, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +} + +declare var _: Combinators; +>_ : Symbol(_, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 15, 11)) +>Combinators : Symbol(Combinators, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 8, 1)) + +declare var c2: Collection; +>c2 : Symbol(c2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 16, 11)) +>Collection : Symbol(Collection, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 0, 9)) + +var rf1 = (x: number) => { return x.toFixed() }; +>rf1 : Symbol(rf1, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 18, 3)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 18, 11)) +>x.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 18, 11)) +>toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) + +var r1a = _.map(c2, (x) => { return x.toFixed() }); +>r1a : Symbol(r1a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 19, 3)) +>_.map : Symbol(Combinators.map, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 9, 23), Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 10, 63)) +>_ : Symbol(_, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 15, 11)) +>map : Symbol(Combinators.map, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 9, 23), Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 10, 63)) +>c2 : Symbol(c2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 16, 11)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 19, 21)) +>x.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 19, 21)) +>toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) + +var r5 = _.forEach(c2, rf1); // Should error +>r5 : Symbol(r5, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 20, 3)) +>_.forEach : Symbol(Combinators.forEach, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 11, 64)) +>_ : Symbol(_, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 15, 11)) +>forEach : Symbol(Combinators.forEach, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 11, 64)) +>c2 : Symbol(c2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 16, 11)) +>rf1 : Symbol(rf1, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 18, 3)) + +var r6 = _.forEach(c2, (x) => { return x.toFixed() }); // Should error +>r6 : Symbol(r6, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 21, 3)) +>_.forEach : Symbol(Combinators.forEach, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 11, 64)) +>_ : Symbol(_, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 15, 11)) +>forEach : Symbol(Combinators.forEach, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 11, 64)) +>c2 : Symbol(c2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 16, 11)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 21, 32)) +>x.toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 21, 32)) +>toFixed : Symbol(Number.toFixed, Decl(lib.d.ts, --, --)) + +declare const zipWith: (a: T[], b: S[], f: (x: T) => (y: S) => U) => U[]; +>zipWith : Symbol(zipWith, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 22, 13)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 22, 24)) +>S : Symbol(S, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 22, 26)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 22, 29)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 22, 33)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 22, 24)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 22, 40)) +>S : Symbol(S, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 22, 26)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 22, 48)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 22, 53)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 22, 24)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 22, 63)) +>S : Symbol(S, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 22, 26)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 22, 29)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 22, 29)) + +declare const pair: (x: T) => (y: S) => { x: T; y: S; } +>pair : Symbol(pair, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 23, 13)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 23, 21)) +>S : Symbol(S, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 23, 23)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 23, 27)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 23, 21)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 23, 37)) +>S : Symbol(S, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 23, 23)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 23, 47)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 23, 21)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 23, 53)) +>S : Symbol(S, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 23, 23)) + +const zr = zipWith([1, 2], ['a', 'b'], pair); +>zr : Symbol(zr, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 24, 5)) +>zipWith : Symbol(zipWith, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 22, 13)) +>pair : Symbol(pair, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 23, 13)) + +declare function lego1(x: A, l: List, y: A): A; +>lego1 : Symbol(lego1, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 24, 45)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 26, 23)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 26, 25)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 26, 29)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 26, 23)) +>l : Symbol(l, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 26, 34)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 26, 25)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 26, 46)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 26, 23)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 26, 23)) + +declare function lego2(f: (l: List, x: D, y: D) => D): void; +>lego2 : Symbol(lego2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 26, 56)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 27, 23)) +>D : Symbol(D, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 27, 25)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 27, 29)) +>l : Symbol(l, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 27, 33)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 27, 23)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 27, 44)) +>D : Symbol(D, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 27, 25)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 27, 50)) +>D : Symbol(D, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 27, 25)) +>D : Symbol(D, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 27, 25)) + +lego2(lego1); +>lego2 : Symbol(lego2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 26, 56)) +>lego1 : Symbol(lego1, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 24, 45)) + +declare function bombastic(f: (x: string, y: number) => R): R; +>bombastic : Symbol(bombastic, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 28, 13)) +>R : Symbol(R, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 30, 27)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 30, 30)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 30, 34)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 30, 44)) +>R : Symbol(R, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 30, 27)) +>R : Symbol(R, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 30, 27)) + +declare function bombastic2(f: (x: string, y: number) => string): void; +>bombastic2 : Symbol(bombastic2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 30, 65)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 31, 28)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 31, 32)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 31, 42)) + +declare function bombastic3(f: (x: string, y: number, z: R) => R): R; +>bombastic3 : Symbol(bombastic3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 31, 71)) +>R : Symbol(R, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 32, 28)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 32, 31)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 32, 35)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 32, 45)) +>z : Symbol(z, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 32, 56)) +>R : Symbol(R, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 32, 28)) +>R : Symbol(R, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 32, 28)) +>R : Symbol(R, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 32, 28)) + +declare function okay(f: (x: 1, y: number) => R): R; +>okay : Symbol(okay, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 32, 72)) +>R : Symbol(R, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 33, 22)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 33, 25)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 33, 29)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 33, 34)) +>R : Symbol(R, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 33, 22)) +>R : Symbol(R, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 33, 22)) + +declare function transitive(x: T, f: (x: T) => T): void; +>transitive : Symbol(transitive, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 33, 55)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 34, 28)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 34, 31)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 34, 28)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 34, 36)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 34, 41)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 34, 28)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 34, 28)) + +bombastic(id2); // Should be an error T = [string, number] +>bombastic : Symbol(bombastic, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 28, 13)) +>id2 : Symbol(id2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 68)) + +bombastic2(id2); // Should be an error T = [string, number] +>bombastic2 : Symbol(bombastic2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 30, 65)) +>id2 : Symbol(id2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 68)) + +bombastic(id2); // should be an error because bombastic's callback is (x: string, y: number) => R and the explicit type argument here is setting `R`, not setting T and U from id2 +>bombastic : Symbol(bombastic, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 28, 13)) +>id2 : Symbol(id2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 68)) + +declare function id3(x: T, y: U, z: V): V; +>id3 : Symbol(id3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 38, 30)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 39, 21)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 39, 23)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 39, 21)) +>V : Symbol(V, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 39, 36)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 39, 23)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 39, 50)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 39, 21)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 39, 55)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 39, 23)) +>z : Symbol(z, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 39, 61)) +>V : Symbol(V, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 39, 36)) +>V : Symbol(V, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 39, 36)) + +bombastic3(id3); // Should be error +>bombastic3 : Symbol(bombastic3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 31, 71)) +>id3 : Symbol(id3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 38, 30)) + +bombastic3(id3); // Should be error because of reason from bombastic(id2) +>bombastic3 : Symbol(bombastic3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 31, 71)) +>id3 : Symbol(id3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 38, 30)) + +okay(id2); +>okay : Symbol(okay, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 32, 72)) +>id2 : Symbol(id2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 68)) + +transitive(1, withNum); +>transitive : Symbol(transitive, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 33, 55)) +>withNum : Symbol(withNum, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 123, 40)) + +transitive('1', withNum); +>transitive : Symbol(transitive, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 33, 55)) +>withNum : Symbol(withNum, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 123, 40)) + +declare function occurs(f: (x: number, xs: List) => R): R; +>occurs : Symbol(occurs, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 44, 25)) +>R : Symbol(R, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 46, 24)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 46, 27)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 46, 31)) +>xs : Symbol(xs, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 46, 41)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>R : Symbol(R, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 46, 24)) +>R : Symbol(R, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 46, 24)) + +occurs(id2); // should be error +>occurs : Symbol(occurs, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 44, 25)) +>id2 : Symbol(id2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 68)) + +declare function f15(x: T, f: (x: T) => T): void; +>f15 : Symbol(f15, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 47, 12)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 49, 21)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 49, 39)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 49, 21)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 49, 44)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 49, 49)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 49, 21)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 49, 21)) + +declare function g15(n: number): number; +>g15 : Symbol(g15, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 49, 67)) +>n : Symbol(n, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 50, 21)) + +f15(5, g15); +>f15 : Symbol(f15, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 47, 12)) +>g15 : Symbol(g15, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 49, 67)) + +interface J { +>J : Symbol(J, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 51, 12)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 53, 12)) + + [s: string]: T; +>s : Symbol(s, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 54, 5)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 53, 12)) +} + +declare function g1(obj: J): T; +>g1 : Symbol(g1, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 55, 1)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 57, 20)) +>obj : Symbol(obj, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 57, 23)) +>J : Symbol(J, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 51, 12)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 57, 20)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 57, 20)) + +const rg1: string = g1({ p: "" }); +>rg1 : Symbol(rg1, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 58, 5)) +>g1 : Symbol(g1, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 55, 1)) +>p : Symbol(p, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 58, 24)) + +declare function forEachChild(node: Node, cbNode: (node: Node) => T | undefined, cbNodeArray?: (nodes: NodeArray) => T | undefined): T | undefined; +>forEachChild : Symbol(forEachChild, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 58, 34)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 60, 30)) +>node : Symbol(node, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 60, 33)) +>Node : Symbol(Node, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 60, 156)) +>cbNode : Symbol(cbNode, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 60, 44)) +>node : Symbol(node, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 60, 54)) +>Node : Symbol(Node, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 60, 156)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 60, 30)) +>cbNodeArray : Symbol(cbNodeArray, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 60, 83)) +>nodes : Symbol(nodes, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 60, 99)) +>NodeArray : Symbol(NodeArray, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 76, 1)) +>Node : Symbol(Node, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 60, 156)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 60, 30)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 60, 30)) + +class Node { +>Node : Symbol(Node, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 60, 156)) + + _node: any; +>_node : Symbol(Node._node, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 62, 12)) + + forEachChild(cbNode: (node: Node) => C, cbNodeArray?: (nodes: NodeArray) => C): C { +>forEachChild : Symbol(Node.forEachChild, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 63, 15)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 65, 17)) +>cbNode : Symbol(cbNode, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 65, 20)) +>node : Symbol(node, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 65, 29)) +>Node : Symbol(Node, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 60, 156)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 65, 17)) +>cbNodeArray : Symbol(cbNodeArray, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 65, 46)) +>nodes : Symbol(nodes, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 65, 62)) +>NodeArray : Symbol(NodeArray, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 76, 1)) +>Node : Symbol(Node, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 60, 156)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 65, 17)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 65, 17)) + + return forEachChild(this, cbNode, cbNodeArray); +>forEachChild : Symbol(forEachChild, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 58, 34)) +>this : Symbol(Node, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 60, 156)) +>cbNode : Symbol(cbNode, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 65, 20)) +>cbNodeArray : Symbol(cbNodeArray, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 65, 46)) + } +} + +interface NodeBrand { _nodearray: any } +>NodeBrand : Symbol(NodeBrand, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 68, 1)) +>_nodearray : Symbol(NodeBrand._nodearray, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 70, 21)) + +class Declaration extends Node { _declarationBrand: any; } +>Declaration : Symbol(Declaration, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 70, 39)) +>Node : Symbol(Node, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 60, 156)) +>_declarationBrand : Symbol(Declaration._declarationBrand, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 71, 32)) + +class ParameterDeclaration extends Declaration { _paramdecl: any; } +>ParameterDeclaration : Symbol(ParameterDeclaration, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 71, 58)) +>Declaration : Symbol(Declaration, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 70, 39)) +>_paramdecl : Symbol(ParameterDeclaration._paramdecl, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 72, 48)) + +interface Arr { +>Arr : Symbol(Arr, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 72, 67)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 73, 14)) + + concat(...items: T[][]): T[]; +>concat : Symbol(Arr.concat, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 73, 18), Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 74, 33)) +>items : Symbol(items, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 74, 11)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 73, 14)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 73, 14)) + + concat(...items: (T | T[])[]): T[]; +>concat : Symbol(Arr.concat, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 73, 18), Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 74, 33)) +>items : Symbol(items, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 75, 11)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 73, 14)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 73, 14)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 73, 14)) +} +interface NodeArray extends Arr, NodeBrand { } +>NodeArray : Symbol(NodeArray, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 76, 1)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 77, 20)) +>Node : Symbol(Node, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 60, 156)) +>Arr : Symbol(Arr, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 72, 67)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 77, 20)) +>NodeBrand : Symbol(NodeBrand, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 68, 1)) + +declare function indexOf(hay: Arr, needle: T): number; +>indexOf : Symbol(indexOf, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 77, 65)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 79, 25)) +>hay : Symbol(hay, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 79, 28)) +>Arr : Symbol(Arr, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 72, 67)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 79, 25)) +>needle : Symbol(needle, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 79, 40)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 79, 25)) + +declare const fps: NodeArray; +>fps : Symbol(fps, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 80, 13)) +>NodeArray : Symbol(NodeArray, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 76, 1)) +>ParameterDeclaration : Symbol(ParameterDeclaration, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 71, 58)) + +declare const node: Node; +>node : Symbol(node, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 81, 13)) +>Node : Symbol(Node, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 60, 156)) + +indexOf(fps, node); +>indexOf : Symbol(indexOf, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 77, 65)) +>fps : Symbol(fps, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 80, 13)) +>node : Symbol(node, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 81, 13)) + +function selfRef(n: number, callback: (n: number) => T): T { +>selfRef : Symbol(selfRef, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 83, 19)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 85, 17)) +>n : Symbol(n, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 85, 20)) +>callback : Symbol(callback, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 85, 30)) +>n : Symbol(n, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 85, 42)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 85, 17)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 85, 17)) + + return selfRef(n, callback); +>selfRef : Symbol(selfRef, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 83, 19)) +>n : Symbol(n, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 85, 20)) +>callback : Symbol(callback, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 85, 30)) +} + +class A { x: any; } +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 87, 1)) +>x : Symbol(A.x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 89, 9)) + +class B extends A { y: any; } +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 89, 19)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 87, 1)) +>y : Symbol(B.y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 90, 19)) + +class Chain { +>Chain : Symbol(Chain, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 90, 29)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 91, 12)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 87, 1)) + + then(cb: (x: T) => S): Chain { +>then : Symbol(Chain.then, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 91, 26)) +>S : Symbol(S, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 92, 9)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 91, 12)) +>cb : Symbol(cb, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 92, 22)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 92, 27)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 91, 12)) +>S : Symbol(S, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 92, 9)) +>Chain : Symbol(Chain, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 90, 29)) +>S : Symbol(S, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 92, 9)) + + return null!; + } +} + +declare const chainB: Chain; +>chainB : Symbol(chainB, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 97, 13)) +>Chain : Symbol(Chain, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 90, 29)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 89, 19)) + +chainB.then(b => new A); +>chainB.then : Symbol(Chain.then, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 91, 26)) +>chainB : Symbol(chainB, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 97, 13)) +>then : Symbol(Chain.then, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 91, 26)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 98, 12)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 87, 1)) + + +declare function f16(f: (x: number) => 4): void; +>f16 : Symbol(f16, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 98, 24)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 101, 21)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 101, 25)) + +declare function g16(x: number): number; +>g16 : Symbol(g16, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 101, 48)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 102, 21)) + +f16(g16); +>f16 : Symbol(f16, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 98, 24)) +>g16 : Symbol(g16, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 101, 48)) + + +declare function trans(f: (x: T) => string): number; +>trans : Symbol(trans, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 103, 9)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 106, 23)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 106, 26)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 106, 30)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 106, 23)) + +// TODO: these should all be noImplicitAny / destructuring erros +trans(({a}) => a); +>trans : Symbol(trans, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 103, 9)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 108, 8)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 108, 8)) + +trans(([b,c]) => 'foo'); +>trans : Symbol(trans, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 103, 9)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 109, 8)) +>c : Symbol(c, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 109, 10)) + +trans(({d: [e,f]}) => 'foo'); +>trans : Symbol(trans, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 103, 9)) +>d : Symbol(d) +>e : Symbol(e, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 110, 12)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 110, 14)) + +trans(([{g},{h}]) => 'foo'); +>trans : Symbol(trans, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 103, 9)) +>g : Symbol(g, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 111, 9)) +>h : Symbol(h, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 111, 13)) + +trans(({a, b = 10}) => a); +>trans : Symbol(trans, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 103, 9)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 112, 8)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 112, 10)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 112, 8)) + +declare function idCreator(f: (x: T|undefined) => T): T; +>idCreator : Symbol(idCreator, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 112, 26)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 114, 27)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 114, 30)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 114, 34)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 114, 27)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 114, 27)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 114, 27)) + +const icn: number = idCreator(_ => 5); // ZZZ +>icn : Symbol(icn, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 115, 5)) +>idCreator : Symbol(idCreator, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 112, 26)) +>_ : Symbol(_, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 115, 30)) + +declare function bar(x: T, y: U, cb: (x: T, y: U) => V): V; +>bar : Symbol(bar, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 115, 38)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 21)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 23)) +>V : Symbol(V, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 26)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 30)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 21)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 35)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 23)) +>cb : Symbol(cb, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 41)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 47)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 21)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 52)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 23)) +>V : Symbol(V, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 26)) +>V : Symbol(V, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 26)) + +// having a second type parameter extend the first should prevent it from inferring a "string | number" union type from (x: string, y: number) => R +declare function id2(x: T, y: U): U; +>id2 : Symbol(id2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 68)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 118, 21)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 118, 23)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 118, 21)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 118, 37)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 118, 21)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 118, 42)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 118, 23)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 118, 23)) + +var b2 = bar(1, "one", id2); // Should be error +>b2 : Symbol(b2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 119, 3)) +>bar : Symbol(bar, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 115, 38)) +>id2 : Symbol(id2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 116, 68)) + + +declare function id2OneTypeParam(x: T, y: T): T; +>id2OneTypeParam : Symbol(id2OneTypeParam, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 119, 28)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 122, 33)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 122, 36)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 122, 33)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 122, 41)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 122, 33)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 122, 33)) + +var b4 = bar(1, "one", id2OneTypeParam); // Should be number | string +>b4 : Symbol(b4, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 123, 3)) +>bar : Symbol(bar, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 115, 38)) +>id2OneTypeParam : Symbol(id2OneTypeParam, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 119, 28)) + + + +declare function withNum(x: N): N; +>withNum : Symbol(withNum, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 123, 40)) +>N : Symbol(N, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 127, 25)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 127, 43)) +>N : Symbol(N, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 127, 25)) +>N : Symbol(N, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 127, 25)) + +declare function withString(f: (x: S) => S): void; +>withString : Symbol(withString, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 127, 52)) +>S : Symbol(S, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 128, 28)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 128, 46)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 128, 50)) +>S : Symbol(S, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 128, 28)) +>S : Symbol(S, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 128, 28)) + +declare function useString(f: (x: string) => string): void; +>useString : Symbol(useString, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 128, 68)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 129, 27)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 129, 31)) + +withString(withNum); // Error +>withString : Symbol(withString, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 127, 52)) +>withNum : Symbol(withNum, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 123, 40)) + +useString(withNum); // Error +>useString : Symbol(useString, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 128, 68)) +>withNum : Symbol(withNum, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 123, 40)) + +declare function f10(x: T): T; +>f10 : Symbol(f10, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 132, 19), Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 133, 33)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 133, 21)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 133, 24)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 133, 21)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 133, 21)) + +declare function f10(x: T, y: number): T; +>f10 : Symbol(f10, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 132, 19), Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 133, 33)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 134, 21)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 134, 24)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 134, 21)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 134, 29)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 134, 21)) + +const a10: string[] = ["a", "b"]; +>a10 : Symbol(a10, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 136, 5)) + +const b10 = a10.map(f10); +>b10 : Symbol(b10, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 137, 5)) +>a10.map : Symbol(Array.map, Decl(lib.d.ts, --, --)) +>a10 : Symbol(a10, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 136, 5)) +>map : Symbol(Array.map, Decl(lib.d.ts, --, --)) +>f10 : Symbol(f10, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 132, 19), Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 133, 33)) + +declare function botox(idX: (x: X) => X, idY: (y: Y) => Y): (x: X, y: Y) => [X, Y]; +>botox : Symbol(botox, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 137, 25)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 139, 23)) +>Y : Symbol(Y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 139, 25)) +>idX : Symbol(idX, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 139, 29)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 139, 35)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 139, 23)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 139, 23)) +>idY : Symbol(idY, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 139, 46)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 139, 53)) +>Y : Symbol(Y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 139, 25)) +>Y : Symbol(Y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 139, 25)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 139, 67)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 139, 23)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 139, 72)) +>Y : Symbol(Y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 139, 25)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 139, 23)) +>Y : Symbol(Y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 139, 25)) + +const xyPair: [number, string] = botox(id, id)(3, 'str'); +>xyPair : Symbol(xyPair, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 140, 5)) +>botox : Symbol(botox, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 137, 25)) +>id : Symbol(id, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 72)) +>id : Symbol(id, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 72)) + +const testPair: { x: number, y: string } = pair(3)('str'); +>testPair : Symbol(testPair, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 141, 5)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 141, 17)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 141, 28)) +>pair : Symbol(pair, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 23, 13)) + +declare function botox2(idX: { a: (x: X) => X }, idY: { a: (y: Y) => Y }): (x: X, y: Y) => [X, Y]; +>botox2 : Symbol(botox2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 141, 58)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 143, 24)) +>Y : Symbol(Y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 143, 26)) +>idX : Symbol(idX, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 143, 30)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 143, 36)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 143, 41)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 143, 24)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 143, 24)) +>idY : Symbol(idY, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 143, 54)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 143, 61)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 143, 66)) +>Y : Symbol(Y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 143, 26)) +>Y : Symbol(Y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 143, 26)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 143, 82)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 143, 24)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 143, 87)) +>Y : Symbol(Y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 143, 26)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 143, 24)) +>Y : Symbol(Y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 143, 26)) + +const bottoxObj = { a: id }; +>bottoxObj : Symbol(bottoxObj, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 145, 5)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 145, 19)) +>id : Symbol(id, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 72)) + +const xyPair2: [number, string] = botox2(bottoxObj, bottoxObj)(3, 'str'); // ZZZ +>xyPair2 : Symbol(xyPair2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 146, 5)) +>botox2 : Symbol(botox2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 141, 58)) +>bottoxObj : Symbol(bottoxObj, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 145, 5)) +>bottoxObj : Symbol(bottoxObj, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 145, 5)) + +const xyPair3: [number, string] = botox2({ a: id }, { a: id })(3, 'str'); +>xyPair3 : Symbol(xyPair3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 147, 5)) +>botox2 : Symbol(botox2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 141, 58)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 147, 42)) +>id : Symbol(id, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 72)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 147, 53)) +>id : Symbol(id, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 72)) + + +class GenericClass { +>GenericClass : Symbol(GenericClass, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 147, 73)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 150, 19)) + + payload: T; +>payload : Symbol(GenericClass.payload, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 150, 23)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 150, 19)) +} + +var genericObject = new GenericClass<{ greeting: string }>(); +>genericObject : Symbol(genericObject, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 154, 3)) +>GenericClass : Symbol(GenericClass, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 147, 73)) +>greeting : Symbol(greeting, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 154, 38)) + +function genericFunction(object: GenericClass, callback: (payload: T) => void) { +>genericFunction : Symbol(genericFunction, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 154, 61)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 156, 25)) +>object : Symbol(object, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 156, 28)) +>GenericClass : Symbol(GenericClass, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 147, 73)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 156, 25)) +>callback : Symbol(callback, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 156, 52)) +>payload : Symbol(payload, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 156, 64)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 156, 25)) + + callback(object.payload); +>callback : Symbol(callback, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 156, 52)) +>object.payload : Symbol(GenericClass.payload, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 150, 23)) +>object : Symbol(object, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 156, 28)) +>payload : Symbol(GenericClass.payload, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 150, 23)) +} + +genericFunction(genericObject, ({greeting}) => { +>genericFunction : Symbol(genericFunction, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 154, 61)) +>genericObject : Symbol(genericObject, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 154, 3)) +>greeting : Symbol(greeting, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 160, 33)) + + var s = greeting.toLocaleLowerCase(); // Greeting should be of type string +>s : Symbol(s, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 161, 7)) +>greeting.toLocaleLowerCase : Symbol(String.toLocaleLowerCase, Decl(lib.d.ts, --, --)) +>greeting : Symbol(greeting, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 160, 33)) +>toLocaleLowerCase : Symbol(String.toLocaleLowerCase, Decl(lib.d.ts, --, --)) + +}); + +class Foo{ +>Foo : Symbol(Foo, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 162, 3)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 164, 10)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 164, 21)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 164, 31)) + + test: T; +>test : Symbol(Foo.test, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 164, 44)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 164, 10)) + + constructor(x: T){} +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 166, 16)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 164, 10)) +} + +var x = new Foo(true); // Should error +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 169, 3)) +>Foo : Symbol(Foo, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 162, 3)) + +var y = new Foo({a: "test", b: 42}); // Should be OK +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 170, 3)) +>Foo : Symbol(Foo, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 162, 3)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 170, 17)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 170, 27)) + +var z: number = y.test.b; +>z : Symbol(z, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 171, 3), Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 315, 3)) +>y.test.b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 170, 27)) +>y.test : Symbol(Foo.test, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 164, 44)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 170, 3)) +>test : Symbol(Foo.test, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 164, 44)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 170, 27)) + +declare function withFew(values: a[], haveFew: (values: a[]) => r, haveNone: (reason: string) => r): r; +>withFew : Symbol(withFew, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 171, 25)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 173, 25)) +>r : Symbol(r, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 173, 27)) +>values : Symbol(values, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 173, 31)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 173, 25)) +>haveFew : Symbol(haveFew, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 173, 43)) +>values : Symbol(values, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 173, 54)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 173, 25)) +>r : Symbol(r, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 173, 27)) +>haveNone : Symbol(haveNone, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 173, 72)) +>reason : Symbol(reason, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 173, 84)) +>r : Symbol(r, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 173, 27)) +>r : Symbol(r, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 173, 27)) + +function fail(message: string) : never { throw new Error(message); } +>fail : Symbol(fail, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 173, 109)) +>message : Symbol(message, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 174, 14)) +>Error : Symbol(Error, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>message : Symbol(message, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 174, 14)) + +const result: number[] = withFew([1, 2, 3], id, fail); // expected result is number[] +>result : Symbol(result, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 5)) +>withFew : Symbol(withFew, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 171, 25)) +>id : Symbol(id, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 72)) +>fail : Symbol(fail, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 173, 109)) + +type List = { kind: 'nil' } +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 176, 10)) +>kind : Symbol(kind, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 176, 16)) + + | { kind: 'cons', val: T, rest: List } +>kind : Symbol(kind, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 177, 16)) +>val : Symbol(val, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 177, 30)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 176, 10)) +>rest : Symbol(rest, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 177, 38)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 176, 10)) + +const Nil = { kind: 'nil' as 'nil' } +>Nil : Symbol(Nil, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 179, 5)) +>kind : Symbol(kind, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 179, 13)) + +declare function cons(x: C, xs: List): List; +>cons : Symbol(cons, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 179, 36)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 181, 22)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 181, 25)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 181, 22)) +>xs : Symbol(xs, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 181, 30)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 181, 22)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 181, 22)) + +declare function foldr(list: List, initial: A, f: (x: V, acc: A) => A): A; +>foldr : Symbol(foldr, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 181, 53)) +>V : Symbol(V, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 182, 23)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 182, 25)) +>list : Symbol(list, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 182, 29)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>V : Symbol(V, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 182, 23)) +>initial : Symbol(initial, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 182, 43)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 182, 25)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 182, 55)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 182, 60)) +>V : Symbol(V, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 182, 23)) +>acc : Symbol(acc, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 182, 65)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 182, 25)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 182, 25)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 182, 25)) + +function concat(list: List>): List { +>concat : Symbol(concat, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 182, 83)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 184, 16)) +>list : Symbol(list, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 184, 19)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 184, 16)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 184, 16)) + + return foldr(list, Nil as List, append); +>foldr : Symbol(foldr, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 181, 53)) +>list : Symbol(list, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 184, 19)) +>Nil : Symbol(Nil, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 179, 5)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 184, 16)) +>append : Symbol(append, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 186, 1)) +} + +function append(xs: List, ys: List): List { +>append : Symbol(append, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 186, 1)) +>L : Symbol(L, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 188, 16)) +>xs : Symbol(xs, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 188, 19)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>L : Symbol(L, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 188, 16)) +>ys : Symbol(ys, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 188, 31)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>L : Symbol(L, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 188, 16)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>L : Symbol(L, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 188, 16)) + + return foldr(xs, ys, cons); +>foldr : Symbol(foldr, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 181, 53)) +>xs : Symbol(xs, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 188, 19)) +>ys : Symbol(ys, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 188, 31)) +>cons : Symbol(cons, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 179, 36)) +} + +declare function zest(x: T): void; +>zest : Symbol(zest, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 190, 1)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 192, 22)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 192, 25)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 192, 22)) + +zest(5); // should be number +>zest : Symbol(zest, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 190, 1)) + +function append2(xs: List, ys: List): List { +>append2 : Symbol(append2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 193, 8)) +>L : Symbol(L, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 194, 17)) +>xs : Symbol(xs, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 194, 20)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>L : Symbol(L, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 194, 17)) +>ys : Symbol(ys, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 194, 32)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>L : Symbol(L, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 194, 17)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>L : Symbol(L, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 194, 17)) + + return foldr(xs, ys, flip(fconst)); // ZZZ +>foldr : Symbol(foldr, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 181, 53)) +>xs : Symbol(xs, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 194, 20)) +>ys : Symbol(ys, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 194, 32)) +>flip : Symbol(flip, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 260, 25)) +>fconst : Symbol(fconst, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 265, 1)) +} + +function append3(xs: List, ys: List) { +>append3 : Symbol(append3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 196, 1)) +>L : Symbol(L, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 198, 17)) +>xs : Symbol(xs, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 198, 20)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>L : Symbol(L, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 198, 17)) +>ys : Symbol(ys, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 198, 32)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>L : Symbol(L, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 198, 17)) + + return foldr(xs, ys, flip(fconst)); +>foldr : Symbol(foldr, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 181, 53)) +>xs : Symbol(xs, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 198, 20)) +>ys : Symbol(ys, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 198, 32)) +>flip : Symbol(flip, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 260, 25)) +>fconst : Symbol(fconst, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 265, 1)) +} + +function append4(xs: List, ys: List) { +>append4 : Symbol(append4, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 200, 1)) +>L : Symbol(L, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 202, 17)) +>xs : Symbol(xs, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 202, 20)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>L : Symbol(L, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 202, 17)) +>ys : Symbol(ys, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 202, 32)) +>List : Symbol(List, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 175, 54)) +>L : Symbol(L, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 202, 17)) + + return foldr(xs, ys, flip(flip(cons))); +>foldr : Symbol(foldr, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 181, 53)) +>xs : Symbol(xs, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 202, 20)) +>ys : Symbol(ys, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 202, 32)) +>flip : Symbol(flip, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 260, 25)) +>flip : Symbol(flip, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 260, 25)) +>cons : Symbol(cons, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 179, 36)) +} + +const infPowa: typeof append = append3; // ZZZ +>infPowa : Symbol(infPowa, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 206, 5)) +>append : Symbol(append, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 186, 1)) +>append3 : Symbol(append3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 196, 1)) + +let jj = (n: T) => 'Error please?'; +>jj : Symbol(jj, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 207, 3)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 207, 10)) +>n : Symbol(n, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 207, 13)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 207, 10)) + +let myFunc: (n: T) => T = jj; +>myFunc : Symbol(myFunc, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 208, 3)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 208, 13)) +>n : Symbol(n, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 208, 16)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 208, 13)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 208, 13)) +>jj : Symbol(jj, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 207, 3)) + +function foo(x: T): T { return x; } +>foo : Symbol(foo, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 208, 32)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 210, 13)) +>Function : Symbol(Function, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 210, 33)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 210, 13)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 210, 13)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 210, 33)) + +const r1 = foo(function (x: string) { return x; }); +>r1 : Symbol(r1, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 211, 5)) +>foo : Symbol(foo, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 208, 32)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 211, 25)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 211, 25)) + +const r2 = foo((x: string) => x); +>r2 : Symbol(r2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 212, 5)) +>foo : Symbol(foo, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 208, 32)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 212, 16)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 212, 16)) + +const r3 = foo(function (x: any) { return x; }); +>r3 : Symbol(r3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 213, 5)) +>foo : Symbol(foo, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 208, 32)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 213, 25)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 213, 25)) + + +declare const cb1: { new (x: T): T }; +>cb1 : Symbol(cb1, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 216, 13)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 216, 26)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 216, 29)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 216, 26)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 216, 26)) + +declare const cb2: { new(x: T): number; new(x: number): T; } +>cb2 : Symbol(cb2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 217, 13)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 217, 25)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 217, 28)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 217, 25)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 217, 47)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 217, 50)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 217, 47)) + +declare const cb3: { new(x: T): number; } +>cb3 : Symbol(cb3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 218, 13)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 218, 25)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 218, 28)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 218, 25)) + +declare const cb4: { new(x: number): T; } +>cb4 : Symbol(cb4, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 219, 13)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 219, 25)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 219, 28)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 219, 25)) + +declare function foo7(x:T, cb: { new(x: T): string; new(x: T, y?: T): string }): void; +>foo7 : Symbol(foo7, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 219, 44)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 220, 22)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 220, 25)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 220, 22)) +>cb : Symbol(cb, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 220, 29)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 220, 40)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 220, 22)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 220, 59)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 220, 22)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 220, 64)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 220, 22)) + +foo7(1, cb1); // Should error (but won't error because type parameters erased when comparing more than one signature) +>foo7 : Symbol(foo7, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 219, 44)) +>cb1 : Symbol(cb1, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 216, 13)) + +foo7(1, cb2); +>foo7 : Symbol(foo7, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 219, 44)) +>cb2 : Symbol(cb2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 217, 13)) + +foo7(1, cb3); +>foo7 : Symbol(foo7, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 219, 44)) +>cb3 : Symbol(cb3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 218, 13)) + +foo7(1, cb4); +>foo7 : Symbol(foo7, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 219, 44)) +>cb4 : Symbol(cb4, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 219, 13)) + +declare function foo8(x:T, cb: { new(x: T): string; }): void; +>foo8 : Symbol(foo8, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 225, 13)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 227, 22)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 227, 25)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 227, 22)) +>cb : Symbol(cb, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 227, 29)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 227, 40)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 227, 22)) + +foo8(1, cb1); // Should error +>foo8 : Symbol(foo8, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 225, 13)) +>cb1 : Symbol(cb1, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 216, 13)) + +foo8(1, cb2); +>foo8 : Symbol(foo8, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 225, 13)) +>cb2 : Symbol(cb2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 217, 13)) + +foo8(1, cb3); +>foo8 : Symbol(foo8, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 225, 13)) +>cb3 : Symbol(cb3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 218, 13)) + +foo8(1, cb4); +>foo8 : Symbol(foo8, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 225, 13)) +>cb4 : Symbol(cb4, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 219, 13)) + +declare function foo9(x:T, cb: { new(x: T, y?: T): string }): void; +>foo9 : Symbol(foo9, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 231, 13)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 233, 22)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 233, 25)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 233, 22)) +>cb : Symbol(cb, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 233, 29)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 233, 40)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 233, 22)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 233, 45)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 233, 22)) + +foo9(1, cb1); // Should error +>foo9 : Symbol(foo9, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 231, 13)) +>cb1 : Symbol(cb1, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 216, 13)) + +foo9(1, cb2); +>foo9 : Symbol(foo9, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 231, 13)) +>cb2 : Symbol(cb2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 217, 13)) + +foo9(1, cb3); +>foo9 : Symbol(foo9, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 231, 13)) +>cb3 : Symbol(cb3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 218, 13)) + +foo9(1, cb4); +>foo9 : Symbol(foo9, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 231, 13)) +>cb4 : Symbol(cb4, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 219, 13)) + +function map(items: A[], f: (x: A) => B): B[]{ +>map : Symbol(map, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 237, 13)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 239, 13)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 239, 15)) +>items : Symbol(items, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 239, 19)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 239, 13)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 239, 30)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 239, 35)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 239, 13)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 239, 15)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 239, 15)) + + return items.map(f); +>items.map : Symbol(Array.map, Decl(lib.d.ts, --, --)) +>items : Symbol(items, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 239, 19)) +>map : Symbol(Array.map, Decl(lib.d.ts, --, --)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 239, 30)) +} + +var v10: number[] = map([1, 2, 3], id); // Error if not number[] +>v10 : Symbol(v10, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 243, 3)) +>map : Symbol(map, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 237, 13)) +>id : Symbol(id, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 72)) + +function foo3(x: T, cb: (a: T) => U, y: U) { +>foo3 : Symbol(foo3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 243, 39)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 244, 14)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 244, 16)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 244, 20)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 244, 14)) +>cb : Symbol(cb, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 244, 25)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 244, 31)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 244, 14)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 244, 16)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 244, 42)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 244, 16)) + + return cb(x); +>cb : Symbol(cb, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 244, 25)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 244, 20)) +} + +var r7 = foo3(1, (a: Z) => '', ''); // string +>r7 : Symbol(r7, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 248, 3)) +>foo3 : Symbol(foo3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 243, 39)) +>Z : Symbol(Z, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 248, 18)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 248, 21)) +>Z : Symbol(Z, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 248, 18)) + +declare var a: { new (x: T): T; }; +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 249, 11)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 249, 22)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 249, 25)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 249, 22)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 249, 22)) + +function foo2(x: T, cb: new(a: T) => U) { +>foo2 : Symbol(foo2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 249, 37)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 250, 14)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 250, 16)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 250, 20)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 250, 14)) +>cb : Symbol(cb, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 250, 25)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 250, 34)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 250, 14)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 250, 16)) + + return new cb(x); +>cb : Symbol(cb, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 250, 25)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 250, 20)) +} + +var r4b = foo2(1, a); // number +>r4b : Symbol(r4b, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 254, 3)) +>foo2 : Symbol(foo2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 249, 37)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 249, 11)) + +function wf(n: N, f: (x: 5) => N): N { +>wf : Symbol(wf, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 254, 21)) +>N : Symbol(N, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 256, 12)) +>n : Symbol(n, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 256, 25)) +>N : Symbol(N, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 256, 12)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 256, 30)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 256, 35)) +>N : Symbol(N, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 256, 12)) +>N : Symbol(N, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 256, 12)) + + return f(n); +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 256, 30)) +>n : Symbol(n, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 256, 25)) +} +const wfr: 5 = wf(5, id); +>wfr : Symbol(wfr, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 259, 5)) +>wf : Symbol(wf, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 254, 21)) +>id : Symbol(id, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 72)) + +const wfr2 = wf(4, id); // error +>wfr2 : Symbol(wfr2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 260, 5)) +>wf : Symbol(wf, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 254, 21)) +>id : Symbol(id, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 72)) + +declare function flip(f: (a: A, b: B) => R): (b: B, a: A) => R; +>flip : Symbol(flip, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 260, 25)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 22)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 24)) +>R : Symbol(R, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 27)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 31)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 35)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 22)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 40)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 24)) +>R : Symbol(R, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 27)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 55)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 24)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 60)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 22)) +>R : Symbol(R, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 27)) + +function id(x: I): I { +>id : Symbol(id, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 72)) +>I : Symbol(I, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 263, 12)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 263, 15)) +>I : Symbol(I, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 263, 12)) +>I : Symbol(I, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 263, 12)) + + return x; +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 263, 15)) +} + +function fconst(x: X, y: Y): X { +>fconst : Symbol(fconst, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 265, 1)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 267, 16)) +>Y : Symbol(Y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 267, 18)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 267, 22)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 267, 16)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 267, 27)) +>Y : Symbol(Y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 267, 18)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 267, 16)) + + return x; +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 267, 22)) +} + +function addStr(x: number, y: string) { +>addStr : Symbol(addStr, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 269, 1)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 271, 16)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 271, 26)) + + return x + y; +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 271, 16)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 271, 26)) +} + +function tagged(tag: T, value: Q): { tag: T, value: Q } { +>tagged : Symbol(tagged, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 273, 1)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 275, 16)) +>Q : Symbol(Q, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 275, 33)) +>tag : Symbol(tag, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 275, 37)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 275, 16)) +>value : Symbol(value, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 275, 44)) +>Q : Symbol(Q, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 275, 33)) +>tag : Symbol(tag, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 275, 57)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 275, 16)) +>value : Symbol(value, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 275, 65)) +>Q : Symbol(Q, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 275, 33)) + + return { tag, value }; +>tag : Symbol(tag, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 276, 12)) +>value : Symbol(value, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 276, 17)) +} + +function fbound(tag: T, value: Q): { tag: T, value: Q } { +>fbound : Symbol(fbound, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 277, 1)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 279, 16)) +>Q : Symbol(Q, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 279, 28)) +>Q : Symbol(Q, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 279, 28)) +>tag : Symbol(tag, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 279, 32)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 279, 16)) +>value : Symbol(value, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 279, 39)) +>Q : Symbol(Q, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 279, 28)) +>tag : Symbol(tag, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 279, 52)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 279, 16)) +>value : Symbol(value, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 279, 60)) +>Q : Symbol(Q, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 279, 28)) + + return { tag, value }; +>tag : Symbol(tag, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 280, 12)) +>value : Symbol(value, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 280, 17)) +} + +fbound(4, 4).tag; // 4 (better) or number +>fbound(4, 4).tag : Symbol(tag, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 279, 52)) +>fbound : Symbol(fbound, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 277, 1)) +>tag : Symbol(tag, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 279, 52)) + +flip(fbound)(4, 4) // OK +>flip : Symbol(flip, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 260, 25)) +>fbound : Symbol(fbound, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 277, 1)) + +fbound(4, "4"); // Error +>fbound : Symbol(fbound, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 277, 1)) + +flip(fbound)("4", 4) // Error +>flip : Symbol(flip, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 260, 25)) +>fbound : Symbol(fbound, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 277, 1)) + +function of2(one: a, two: b): [a, b] { +>of2 : Symbol(of2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 286, 20)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 288, 13)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 288, 15)) +>one : Symbol(one, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 288, 19)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 288, 13)) +>two : Symbol(two, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 288, 26)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 288, 15)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 288, 13)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 288, 15)) + + return [one, two]; +>one : Symbol(one, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 288, 19)) +>two : Symbol(two, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 288, 26)) +} +const flipped = flip(of2); +>flipped : Symbol(flipped, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 291, 5)) +>flip : Symbol(flip, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 260, 25)) +>of2 : Symbol(of2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 286, 20)) + +// it was working before +const f1 = flip(addStr); // (b: string, a: number) => string +>f1 : Symbol(f1, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 294, 5)) +>flip : Symbol(flip, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 260, 25)) +>addStr : Symbol(addStr, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 269, 1)) + +const v1 = f1("hello", 3); +>v1 : Symbol(v1, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 295, 5)) +>f1 : Symbol(f1, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 294, 5)) + +const v2 = id(id)(3); // `3` +>v2 : Symbol(v2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 296, 5)) +>id : Symbol(id, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 72)) +>id : Symbol(id, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 72)) + +// working now +const f2 = flip(id); // (b: {}, a: T): T +>f2 : Symbol(f2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 298, 5)) +>flip : Symbol(flip, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 260, 25)) +>id : Symbol(id, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 72)) + +const f3 = flip(fconst); // (b: Y, a: X) => X +>f3 : Symbol(f3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 299, 5)) +>flip : Symbol(flip, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 260, 25)) +>fconst : Symbol(fconst, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 265, 1)) + +const f4 = flip(tagged); // (b: Q, a: T) => { tag: T, value: Q } +>f4 : Symbol(f4, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 300, 5)) +>flip : Symbol(flip, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 260, 25)) +>tagged : Symbol(tagged, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 273, 1)) + +const v3 = f3(1, "qw") // `"qw"` +>v3 : Symbol(v3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 301, 5)) +>f3 : Symbol(f3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 299, 5)) + +const v4 = f3([], {}) // `{}` +>v4 : Symbol(v4, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 302, 5)) +>f3 : Symbol(f3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 299, 5)) + +const v5 = f4(5, "hello"); // { tag: "hello", value: number } +>v5 : Symbol(v5, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 303, 5)) +>f4 : Symbol(f4, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 300, 5)) + +const v6 = f4(5, 5); // Error as expected +>v6 : Symbol(v6, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 304, 5)) +>f4 : Symbol(f4, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 300, 5)) + +declare function compose(f: (b: B) => C, g: (a: A) => B): (a: A) => C; +>compose : Symbol(compose, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 304, 20)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 305, 25)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 305, 27)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 305, 30)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 305, 34)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 305, 38)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 305, 27)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 305, 30)) +>g : Symbol(g, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 305, 49)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 305, 54)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 305, 25)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 305, 27)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 305, 68)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 305, 25)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 305, 30)) + +declare const f: (x:number) => T; +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 307, 13)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 307, 18)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 307, 21)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 307, 18)) + +declare const g: (x:boolean) => number; +>g : Symbol(g, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 308, 13)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 308, 18)) + +const f5 = compose(f, g) // OUCH! this gets type `(a: boolean) => T` +>f5 : Symbol(f5, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 309, 5)) +>compose : Symbol(compose, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 304, 20)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 307, 13)) +>g : Symbol(g, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 308, 13)) + +declare const g_2: (x: T) => boolean; +>g_2 : Symbol(g_2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 310, 13)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 310, 20)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 310, 23)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 310, 20)) + +declare const f_2: (x: boolean) => number; +>f_2 : Symbol(f_2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 311, 13)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 311, 20)) + +const f6 = compose(f_2, g_2) // (a: T) => number +>f6 : Symbol(f6, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 312, 5)) +>compose : Symbol(compose, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 304, 20)) +>f_2 : Symbol(f_2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 311, 13)) +>g_2 : Symbol(g_2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 310, 13)) + +const f7 = compose(id, x => String(x)) // (a: {}) => string +>f7 : Symbol(f7, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 313, 5)) +>compose : Symbol(compose, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 304, 20)) +>id : Symbol(id, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 72)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 313, 22)) +>String : Symbol(String, Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --), Decl(lib.d.ts, --, --)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 313, 22)) + +declare function h(f: (x: number) => R): R; +>h : Symbol(h, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 313, 38)) +>R : Symbol(R, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 314, 19)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 314, 22)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 314, 26)) +>R : Symbol(R, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 314, 19)) +>R : Symbol(R, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 314, 19)) + +var z: number = h(id); +>z : Symbol(z, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 171, 3), Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 315, 3)) +>h : Symbol(h, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 313, 38)) +>id : Symbol(id, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 72)) + +const arr: number[] = [1, 2, 3].map(id); +>arr : Symbol(arr, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 317, 5)) +>[1, 2, 3].map : Symbol(Array.map, Decl(lib.d.ts, --, --)) +>map : Symbol(Array.map, Decl(lib.d.ts, --, --)) +>id : Symbol(id, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 261, 72)) + +declare const val1: string | undefined; +>val1 : Symbol(val1, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 319, 13)) + +declare function cleanse(x: T|undefined): x is T; +>cleanse : Symbol(cleanse, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 319, 39)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 320, 25)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 320, 28)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 320, 25)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 320, 28)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 320, 25)) + +cleanse(val1); +>cleanse : Symbol(cleanse, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 319, 39)) +>val1 : Symbol(val1, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 319, 13)) + +class MyClass +>MyClass : Symbol(MyClass, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 322, 14)) +{ + one(c: boolean){}; +>one : Symbol(MyClass.one, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 325, 1)) +>c : Symbol(c, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 326, 6)) + + two(){}; +>two : Symbol(MyClass.two, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 326, 20)) +} + +declare const test: PickPrototype; +>test : Symbol(test, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 330, 13)) +>PickPrototype : Symbol(PickPrototype, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 330, 57)) +>MyClass : Symbol(MyClass, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 322, 14)) + +type PickPrototype = { +>PickPrototype : Symbol(PickPrototype, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 330, 57)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 331, 19)) +>prototype : Symbol(prototype, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 331, 30)) +>K : Symbol(K, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 331, 48)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 331, 19)) + + [P in K]: T['prototype'][P]; +>P : Symbol(P, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 332, 5)) +>K : Symbol(K, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 331, 48)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 331, 19)) +>P : Symbol(P, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 332, 5)) +} + + +function wrap(innerFunc: (data: T) => any) { +>wrap : Symbol(wrap, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 333, 1)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 336, 14)) +>innerFunc : Symbol(innerFunc, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 336, 17)) +>data : Symbol(data, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 336, 29)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 336, 14)) + + return (data:T) => innerFunc(data); +>data : Symbol(data, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 337, 12)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 336, 14)) +>innerFunc : Symbol(innerFunc, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 336, 17)) +>data : Symbol(data, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 337, 12)) +} + +function inner(x:number) {}; +>inner : Symbol(inner, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 338, 1)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 340, 15)) + +inner(2); +>inner : Symbol(inner, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 338, 1)) + +let func = wrap(inner); +>func : Symbol(func, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 343, 3)) +>wrap : Symbol(wrap, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 333, 1)) +>inner : Symbol(inner, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 338, 1)) + +func(2); +>func : Symbol(func, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 343, 3)) + + +declare function union(f: (a: A|B|C, b: A|B|C, c: A|B|C) => void): void; +>union : Symbol(union, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 344, 8)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 347, 23)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 347, 25)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 347, 28)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 347, 32)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 347, 36)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 347, 23)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 347, 25)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 347, 28)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 347, 45)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 347, 23)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 347, 25)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 347, 28)) +>c : Symbol(c, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 347, 55)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 347, 23)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 347, 25)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 347, 28)) + +union((x: X, y: Y, z: Z) => x) +>union : Symbol(union, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 344, 8)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 348, 7)) +>Y : Symbol(Y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 348, 9)) +>Z : Symbol(Z, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 348, 12)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 348, 16)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 348, 7)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 348, 21)) +>Y : Symbol(Y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 348, 9)) +>z : Symbol(z, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 348, 27)) +>Z : Symbol(Z, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 348, 12)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 348, 16)) + +declare function union2(f: (a: A, b: B, c: C) => void): void; +>union2 : Symbol(union2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 348, 39)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 350, 24)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 350, 26)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 350, 29)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 350, 33)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 350, 37)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 350, 24)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 350, 42)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 350, 26)) +>c : Symbol(c, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 350, 48)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 350, 29)) + +union2((x: X|Y|Z, y: X|Y|Z, z: X|Y|Z) => x); +>union2 : Symbol(union2, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 348, 39)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 351, 8)) +>Y : Symbol(Y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 351, 10)) +>Z : Symbol(Z, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 351, 13)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 351, 17)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 351, 8)) +>Y : Symbol(Y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 351, 10)) +>Z : Symbol(Z, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 351, 13)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 351, 26)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 351, 8)) +>Y : Symbol(Y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 351, 10)) +>Z : Symbol(Z, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 351, 13)) +>z : Symbol(z, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 351, 36)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 351, 8)) +>Y : Symbol(Y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 351, 10)) +>Z : Symbol(Z, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 351, 13)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 351, 17)) + +declare function union3(f: (a: A|string, b: A|number) => B): B; +>union3 : Symbol(union3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 351, 53)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 353, 24)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 353, 26)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 353, 30)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 353, 34)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 353, 24)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 353, 46)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 353, 24)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 353, 26)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 353, 26)) + +declare function uParam31(x: X|number, y: X|string): X; +>uParam31 : Symbol(uParam31, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 353, 69)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 354, 26)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 354, 29)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 354, 26)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 354, 41)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 354, 26)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 354, 26)) + +declare function uParam32(x: number, y: number|string): void; +>uParam32 : Symbol(uParam32, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 354, 58)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 355, 26)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 355, 36)) + +declare function uParam33(x: string, y: number|string): void; +>uParam33 : Symbol(uParam33, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 355, 61)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 356, 26)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 356, 36)) + +union3(uParam31); // error; A,X = [number, string] +>union3 : Symbol(union3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 351, 53)) +>uParam31 : Symbol(uParam31, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 353, 69)) + +union3(uParam32); // error +>union3 : Symbol(union3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 351, 53)) +>uParam32 : Symbol(uParam32, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 354, 58)) + +union3(uParam33); // OK; A = string; B = void +>union3 : Symbol(union3, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 351, 53)) +>uParam33 : Symbol(uParam33, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 355, 61)) + +declare function union4(f: (b: A|B) => C, a: A): C; +>union4 : Symbol(union4, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 359, 17)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 360, 24)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 360, 26)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 360, 29)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 360, 33)) +>b : Symbol(b, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 360, 37)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 360, 24)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 360, 26)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 360, 29)) +>a : Symbol(a, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 360, 50)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 360, 24)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 360, 29)) + +declare function uParam41(y: number|string): void; +>uParam41 : Symbol(uParam41, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 360, 60)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 361, 26)) + +declare function uParam42(y: number|X): X; +>uParam42 : Symbol(uParam42, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 361, 50)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 362, 26)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 362, 29)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 362, 26)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 362, 26)) + +declare function uParam43(y: string|X): X; +>uParam43 : Symbol(uParam43, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 362, 45)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 363, 26)) +>y : Symbol(y, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 363, 29)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 363, 26)) +>X : Symbol(X, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 363, 26)) + +union4(uParam41, 4); // A = number, B = string, C = void +>union4 : Symbol(union4, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 359, 17)) +>uParam41 : Symbol(uParam41, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 360, 60)) + +union4(uParam42, 4); // A = number, B = X, C = X +>union4 : Symbol(union4, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 359, 17)) +>uParam42 : Symbol(uParam42, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 361, 50)) + +union4(uParam43, 4); // A = number, B = string, C = number +>union4 : Symbol(union4, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 359, 17)) +>uParam43 : Symbol(uParam43, Decl(inferringGenericFunctionsFromGenericFunctions2.ts, 362, 45)) + diff --git a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.types b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.types new file mode 100644 index 0000000000000..456b8de8d2fd9 --- /dev/null +++ b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.types @@ -0,0 +1,1953 @@ +=== tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts === +export {} + +// Borrowed from @gcnew at https://gist.github.com/gcnew/ad833bfa376e4b70fc50a780e3b2d883 + +interface Collection { +>Collection : Collection +>T : T + + length: number; +>length : number + + add(x: T): void; +>add : (x: T) => void +>x : T +>T : T + + remove(x: T): boolean; +>remove : (x: T) => boolean +>x : T +>T : T +} +interface Combinators { +>Combinators : Combinators + + map(c: Collection, f: (x: T) => U): Collection; +>map : { (c: Collection, f: (x: T) => U): Collection; (c: Collection, f: (x: T) => any): Collection; } +>T : T +>U : U +>c : Collection +>Collection : Collection +>T : T +>f : (x: T) => U +>x : T +>T : T +>U : U +>Collection : Collection +>U : U + + map(c: Collection, f: (x: T) => any): Collection; +>map : { (c: Collection, f: (x: T) => U): Collection; (c: Collection, f: (x: T) => any): Collection; } +>T : T +>c : Collection +>Collection : Collection +>T : T +>f : (x: T) => any +>x : T +>T : T +>Collection : Collection + + forEach(c: Collection, f: (x: T) => Date): void; +>forEach : (c: Collection, f: (x: T) => Date) => void +>T : T +>c : Collection +>Collection : Collection +>T : T +>f : (x: T) => Date +>x : T +>T : T +>Date : Date +} + +declare var _: Combinators; +>_ : Combinators +>Combinators : Combinators + +declare var c2: Collection; +>c2 : Collection +>Collection : Collection + +var rf1 = (x: number) => { return x.toFixed() }; +>rf1 : (x: number) => string +>(x: number) => { return x.toFixed() } : (x: number) => string +>x : number +>x.toFixed() : string +>x.toFixed : (fractionDigits?: number | undefined) => string +>x : number +>toFixed : (fractionDigits?: number | undefined) => string + +var r1a = _.map(c2, (x) => { return x.toFixed() }); +>r1a : Collection +>_.map(c2, (x) => { return x.toFixed() }) : Collection +>_.map : { (c: Collection, f: (x: T) => U): Collection; (c: Collection, f: (x: T) => any): Collection; } +>_ : Combinators +>map : { (c: Collection, f: (x: T) => U): Collection; (c: Collection, f: (x: T) => any): Collection; } +>c2 : Collection +>(x) => { return x.toFixed() } : (x: number) => string +>x : number +>x.toFixed() : string +>x.toFixed : (fractionDigits?: number | undefined) => string +>x : number +>toFixed : (fractionDigits?: number | undefined) => string + +var r5 = _.forEach(c2, rf1); // Should error +>r5 : any +>_.forEach(c2, rf1) : any +>_.forEach : (c: Collection, f: (x: T) => Date) => void +>_ : Combinators +>forEach : (c: Collection, f: (x: T) => Date) => void +>c2 : Collection +>rf1 : (x: number) => string + +var r6 = _.forEach(c2, (x) => { return x.toFixed() }); // Should error +>r6 : any +>_.forEach(c2, (x) => { return x.toFixed() }) : any +>_.forEach : (c: Collection, f: (x: T) => Date) => void +>_ : Combinators +>forEach : (c: Collection, f: (x: T) => Date) => void +>c2 : Collection +>(x) => { return x.toFixed() } : (x: number) => string +>x : number +>x.toFixed() : string +>x.toFixed : (fractionDigits?: number | undefined) => string +>x : number +>toFixed : (fractionDigits?: number | undefined) => string + +declare const zipWith: (a: T[], b: S[], f: (x: T) => (y: S) => U) => U[]; +>zipWith : (a: T[], b: S[], f: (x: T) => (y: S) => U) => U[] +>T : T +>S : S +>U : U +>a : T[] +>T : T +>b : S[] +>S : S +>f : (x: T) => (y: S) => U +>x : T +>T : T +>y : S +>S : S +>U : U +>U : U + +declare const pair: (x: T) => (y: S) => { x: T; y: S; } +>pair : (x: T) => (y: S) => { x: T; y: S; } +>T : T +>S : S +>x : T +>T : T +>y : S +>S : S +>x : T +>T : T +>y : S +>S : S + +const zr = zipWith([1, 2], ['a', 'b'], pair); +>zr : { x: number; y: {}; }[] +>zipWith([1, 2], ['a', 'b'], pair) : { x: number; y: {}; }[] +>zipWith : (a: T[], b: S[], f: (x: T) => (y: S) => U) => U[] +>[1, 2] : number[] +>1 : 1 +>2 : 2 +>['a', 'b'] : string[] +>'a' : "a" +>'b' : "b" +>pair : (x: T) => (y: S) => { x: T; y: S; } + +declare function lego1(x: A, l: List, y: A): A; +>lego1 : (x: A, l: List, y: A) => A +>A : A +>B : B +>x : A +>A : A +>l : List +>List : List +>B : B +>y : A +>A : A +>A : A + +declare function lego2(f: (l: List, x: D, y: D) => D): void; +>lego2 : (f: (l: List, x: D, y: D) => D) => void +>C : C +>D : D +>f : (l: List, x: D, y: D) => D +>l : List +>List : List +>C : C +>x : D +>D : D +>y : D +>D : D +>D : D + +lego2(lego1); +>lego2(lego1) : any +>lego2 : (f: (l: List, x: D, y: D) => D) => void +>lego1 : (x: A, l: List, y: A) => A + +declare function bombastic(f: (x: string, y: number) => R): R; +>bombastic : (f: (x: string, y: number) => R) => R +>R : R +>f : (x: string, y: number) => R +>x : string +>y : number +>R : R +>R : R + +declare function bombastic2(f: (x: string, y: number) => string): void; +>bombastic2 : (f: (x: string, y: number) => string) => void +>f : (x: string, y: number) => string +>x : string +>y : number + +declare function bombastic3(f: (x: string, y: number, z: R) => R): R; +>bombastic3 : (f: (x: string, y: number, z: R) => R) => R +>R : R +>f : (x: string, y: number, z: R) => R +>x : string +>y : number +>z : R +>R : R +>R : R +>R : R + +declare function okay(f: (x: 1, y: number) => R): R; +>okay : (f: (x: 1, y: number) => R) => R +>R : R +>f : (x: 1, y: number) => R +>x : 1 +>y : number +>R : R +>R : R + +declare function transitive(x: T, f: (x: T) => T): void; +>transitive : (x: T, f: (x: T) => T) => void +>T : T +>x : T +>T : T +>f : (x: T) => T +>x : T +>T : T +>T : T + +bombastic(id2); // Should be an error T = [string, number] +>bombastic(id2) : any +>bombastic : (f: (x: string, y: number) => R) => R +>id2 : (x: T, y: U) => U + +bombastic2(id2); // Should be an error T = [string, number] +>bombastic2(id2) : void +>bombastic2 : (f: (x: string, y: number) => string) => void +>id2 : (x: T, y: U) => U + +bombastic(id2); // should be an error because bombastic's callback is (x: string, y: number) => R and the explicit type argument here is setting `R`, not setting T and U from id2 +>bombastic(id2) : any +>bombastic : (f: (x: string, y: number) => R) => R +>id2 : (x: T, y: U) => U + +declare function id3(x: T, y: U, z: V): V; +>id3 : (x: T, y: U, z: V) => V +>T : T +>U : U +>T : T +>V : V +>U : U +>x : T +>T : T +>y : U +>U : U +>z : V +>V : V +>V : V + +bombastic3(id3); // Should be error +>bombastic3(id3) : any +>bombastic3 : (f: (x: string, y: number, z: R) => R) => R +>id3 : (x: T, y: U, z: V) => V + +bombastic3(id3); // Should be error because of reason from bombastic(id2) +>bombastic3(id3) : any +>bombastic3 : (f: (x: string, y: number, z: R) => R) => R +>id3 : (x: T, y: U, z: V) => V + +okay(id2); +>okay(id2) : any +>okay : (f: (x: 1, y: number) => R) => R +>id2 : (x: T, y: U) => U + +transitive(1, withNum); +>transitive(1, withNum) : void +>transitive : (x: T, f: (x: T) => T) => void +>1 : 1 +>withNum : (x: N) => N + +transitive('1', withNum); +>transitive('1', withNum) : any +>transitive : (x: T, f: (x: T) => T) => void +>'1' : "1" +>withNum : (x: N) => N + +declare function occurs(f: (x: number, xs: List) => R): R; +>occurs : (f: (x: number, xs: List) => R) => R +>R : R +>f : (x: number, xs: List) => R +>x : number +>xs : List +>List : List +>R : R +>R : R + +occurs(id2); // should be error +>occurs(id2) : any +>occurs : (f: (x: number, xs: List) => R) => R +>id2 : (x: T, y: U) => U + +declare function f15(x: T, f: (x: T) => T): void; +>f15 : (x: T, f: (x: T) => T) => void +>T : T +>x : T +>T : T +>f : (x: T) => T +>x : T +>T : T +>T : T + +declare function g15(n: number): number; +>g15 : (n: number) => number +>n : number + +f15(5, g15); +>f15(5, g15) : void +>f15 : (x: T, f: (x: T) => T) => void +>5 : 5 +>g15 : (n: number) => number + +interface J { +>J : J +>T : T + + [s: string]: T; +>s : string +>T : T +} + +declare function g1(obj: J): T; +>g1 : (obj: J) => T +>T : T +>obj : J +>J : J +>T : T +>T : T + +const rg1: string = g1({ p: "" }); +>rg1 : string +>g1({ p: "" }) : string +>g1 : (obj: J) => T +>{ p: "" } : { p: string; } +>p : string +>"" : "" + +declare function forEachChild(node: Node, cbNode: (node: Node) => T | undefined, cbNodeArray?: (nodes: NodeArray) => T | undefined): T | undefined; +>forEachChild : (node: Node, cbNode: (node: Node) => T | undefined, cbNodeArray?: ((nodes: NodeArray) => T | undefined) | undefined) => T | undefined +>T : T +>node : Node +>Node : Node +>cbNode : (node: Node) => T | undefined +>node : Node +>Node : Node +>T : T +>cbNodeArray : ((nodes: NodeArray) => T | undefined) | undefined +>nodes : NodeArray +>NodeArray : NodeArray +>Node : Node +>T : T +>T : T + +class Node { +>Node : Node + + _node: any; +>_node : any + + forEachChild(cbNode: (node: Node) => C, cbNodeArray?: (nodes: NodeArray) => C): C { +>forEachChild : (cbNode: (node: Node) => C, cbNodeArray?: ((nodes: NodeArray) => C) | undefined) => C +>C : C +>cbNode : (node: Node) => C +>node : Node +>Node : Node +>C : C +>cbNodeArray : ((nodes: NodeArray) => C) | undefined +>nodes : NodeArray +>NodeArray : NodeArray +>Node : Node +>C : C +>C : C + + return forEachChild(this, cbNode, cbNodeArray); +>forEachChild(this, cbNode, cbNodeArray) : C | undefined +>forEachChild : (node: Node, cbNode: (node: Node) => T | undefined, cbNodeArray?: ((nodes: NodeArray) => T | undefined) | undefined) => T | undefined +>this : this +>cbNode : (node: Node) => C +>cbNodeArray : ((nodes: NodeArray) => C) | undefined + } +} + +interface NodeBrand { _nodearray: any } +>NodeBrand : NodeBrand +>_nodearray : any + +class Declaration extends Node { _declarationBrand: any; } +>Declaration : Declaration +>Node : Node +>_declarationBrand : any + +class ParameterDeclaration extends Declaration { _paramdecl: any; } +>ParameterDeclaration : ParameterDeclaration +>Declaration : Declaration +>_paramdecl : any + +interface Arr { +>Arr : Arr +>T : T + + concat(...items: T[][]): T[]; +>concat : { (...items: T[][]): T[]; (...items: (T | T[])[]): T[]; } +>items : T[][] +>T : T +>T : T + + concat(...items: (T | T[])[]): T[]; +>concat : { (...items: T[][]): T[]; (...items: (T | T[])[]): T[]; } +>items : (T | T[])[] +>T : T +>T : T +>T : T +} +interface NodeArray extends Arr, NodeBrand { } +>NodeArray : NodeArray +>T : T +>Node : Node +>Arr : Arr +>T : T +>NodeBrand : NodeBrand + +declare function indexOf(hay: Arr, needle: T): number; +>indexOf : (hay: Arr, needle: T) => number +>T : T +>hay : Arr +>Arr : Arr +>T : T +>needle : T +>T : T + +declare const fps: NodeArray; +>fps : NodeArray +>NodeArray : NodeArray +>ParameterDeclaration : ParameterDeclaration + +declare const node: Node; +>node : Node +>Node : Node + +indexOf(fps, node); +>indexOf(fps, node) : number +>indexOf : (hay: Arr, needle: T) => number +>fps : NodeArray +>node : Node + +function selfRef(n: number, callback: (n: number) => T): T { +>selfRef : (n: number, callback: (n: number) => T) => T +>T : T +>n : number +>callback : (n: number) => T +>n : number +>T : T +>T : T + + return selfRef(n, callback); +>selfRef(n, callback) : T +>selfRef : (n: number, callback: (n: number) => T) => T +>n : number +>callback : (n: number) => T +} + +class A { x: any; } +>A : A +>x : any + +class B extends A { y: any; } +>B : B +>A : A +>y : any + +class Chain { +>Chain : Chain +>T : T +>A : A + + then(cb: (x: T) => S): Chain { +>then : (cb: (x: T) => S) => Chain +>S : S +>T : T +>cb : (x: T) => S +>x : T +>T : T +>S : S +>Chain : Chain +>S : S + + return null!; +>null! : never +>null : null + } +} + +declare const chainB: Chain; +>chainB : Chain +>Chain : Chain +>B : B + +chainB.then(b => new A); +>chainB.then(b => new A) : any +>chainB.then : (cb: (x: B) => S) => Chain +>chainB : Chain +>then : (cb: (x: B) => S) => Chain +>b => new A : (b: B) => A +>b : B +>new A : A +>A : typeof A + + +declare function f16(f: (x: number) => 4): void; +>f16 : (f: (x: number) => 4) => void +>f : (x: number) => 4 +>x : number + +declare function g16(x: number): number; +>g16 : (x: number) => number +>x : number + +f16(g16); +>f16(g16) : void +>f16 : (f: (x: number) => 4) => void +>g16 : (x: number) => number + + +declare function trans(f: (x: T) => string): number; +>trans : (f: (x: T) => string) => number +>T : T +>f : (x: T) => string +>x : T +>T : T + +// TODO: these should all be noImplicitAny / destructuring erros +trans(({a}) => a); +>trans(({a}) => a) : any +>trans : (f: (x: T) => string) => number +>({a}) => a : ({ a }: { a: any; }) => any +>a : any +>a : any + +trans(([b,c]) => 'foo'); +>trans(([b,c]) => 'foo') : any +>trans : (f: (x: T) => string) => number +>([b,c]) => 'foo' : ([b, c]: [any, any]) => string +>b : any +>c : any +>'foo' : "foo" + +trans(({d: [e,f]}) => 'foo'); +>trans(({d: [e,f]}) => 'foo') : any +>trans : (f: (x: T) => string) => number +>({d: [e,f]}) => 'foo' : ({ d: [e, f] }: { d: [any, any]; }) => string +>d : any +>e : any +>f : any +>'foo' : "foo" + +trans(([{g},{h}]) => 'foo'); +>trans(([{g},{h}]) => 'foo') : any +>trans : (f: (x: T) => string) => number +>([{g},{h}]) => 'foo' : ([{ g }, { h }]: [{ g: any; }, { h: any; }]) => string +>g : any +>h : any +>'foo' : "foo" + +trans(({a, b = 10}) => a); +>trans(({a, b = 10}) => a) : any +>trans : (f: (x: T) => string) => number +>({a, b = 10}) => a : ({ a, b }: { a: any; b?: number; }) => any +>a : any +>b : number +>10 : 10 +>a : any + +declare function idCreator(f: (x: T|undefined) => T): T; +>idCreator : (f: (x: T | undefined) => T) => T +>T : T +>f : (x: T | undefined) => T +>x : T | undefined +>T : T +>T : T +>T : T + +const icn: number = idCreator(_ => 5); // ZZZ +>icn : number +>idCreator(_ => 5) : number +>idCreator : (f: (x: T | undefined) => T) => T +>_ => 5 : (_: number | undefined) => number +>_ : number | undefined +>5 : 5 + +declare function bar(x: T, y: U, cb: (x: T, y: U) => V): V; +>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V +>T : T +>U : U +>V : V +>x : T +>T : T +>y : U +>U : U +>cb : (x: T, y: U) => V +>x : T +>T : T +>y : U +>U : U +>V : V +>V : V + +// having a second type parameter extend the first should prevent it from inferring a "string | number" union type from (x: string, y: number) => R +declare function id2(x: T, y: U): U; +>id2 : (x: T, y: U) => U +>T : T +>U : U +>T : T +>x : T +>T : T +>y : U +>U : U +>U : U + +var b2 = bar(1, "one", id2); // Should be error +>b2 : any +>bar(1, "one", id2) : any +>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V +>1 : 1 +>"one" : "one" +>id2 : (x: T, y: U) => U + + +declare function id2OneTypeParam(x: T, y: T): T; +>id2OneTypeParam : (x: T, y: T) => T +>T : T +>x : T +>T : T +>y : T +>T : T +>T : T + +var b4 = bar(1, "one", id2OneTypeParam); // Should be number | string +>b4 : string | number +>bar(1, "one", id2OneTypeParam) : string | number +>bar : (x: T, y: U, cb: (x: T, y: U) => V) => V +>1 : 1 +>"one" : "one" +>id2OneTypeParam : (x: T, y: T) => T + + + +declare function withNum(x: N): N; +>withNum : (x: N) => N +>N : N +>x : N +>N : N +>N : N + +declare function withString(f: (x: S) => S): void; +>withString : (f: (x: S) => S) => void +>S : S +>f : (x: S) => S +>x : S +>S : S +>S : S + +declare function useString(f: (x: string) => string): void; +>useString : (f: (x: string) => string) => void +>f : (x: string) => string +>x : string + +withString(withNum); // Error +>withString(withNum) : any +>withString : (f: (x: S) => S) => void +>withNum : (x: N) => N + +useString(withNum); // Error +>useString(withNum) : void +>useString : (f: (x: string) => string) => void +>withNum : (x: N) => N + +declare function f10(x: T): T; +>f10 : { (x: T): T; (x: T, y: number): T; } +>T : T +>x : T +>T : T +>T : T + +declare function f10(x: T, y: number): T; +>f10 : { (x: T): T; (x: T, y: number): T; } +>T : T +>x : T +>T : T +>y : number +>T : T + +const a10: string[] = ["a", "b"]; +>a10 : string[] +>["a", "b"] : string[] +>"a" : "a" +>"b" : "b" + +const b10 = a10.map(f10); +>b10 : {}[] +>a10.map(f10) : {}[] +>a10.map : (callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[] +>a10 : string[] +>map : (callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[] +>f10 : { (x: T): T; (x: T, y: number): T; } + +declare function botox(idX: (x: X) => X, idY: (y: Y) => Y): (x: X, y: Y) => [X, Y]; +>botox : (idX: (x: X) => X, idY: (y: Y) => Y) => (x: X, y: Y) => [X, Y] +>X : X +>Y : Y +>idX : (x: X) => X +>x : X +>X : X +>X : X +>idY : (y: Y) => Y +>y : Y +>Y : Y +>Y : Y +>x : X +>X : X +>y : Y +>Y : Y +>X : X +>Y : Y + +const xyPair: [number, string] = botox(id, id)(3, 'str'); +>xyPair : [number, string] +>botox(id, id)(3, 'str') : [{}, {}] +>botox(id, id) : (x: {}, y: {}) => [{}, {}] +>botox : (idX: (x: X) => X, idY: (y: Y) => Y) => (x: X, y: Y) => [X, Y] +>id : (x: I) => I +>id : (x: I) => I +>3 : 3 +>'str' : "str" + +const testPair: { x: number, y: string } = pair(3)('str'); +>testPair : { x: number; y: string; } +>x : number +>y : string +>pair(3)('str') : { x: number; y: {}; } +>pair(3) : (y: {}) => { x: number; y: {}; } +>pair : (x: T) => (y: S) => { x: T; y: S; } +>3 : 3 +>'str' : "str" + +declare function botox2(idX: { a: (x: X) => X }, idY: { a: (y: Y) => Y }): (x: X, y: Y) => [X, Y]; +>botox2 : (idX: { a: (x: X) => X; }, idY: { a: (y: Y) => Y; }) => (x: X, y: Y) => [X, Y] +>X : X +>Y : Y +>idX : { a: (x: X) => X; } +>a : (x: X) => X +>x : X +>X : X +>X : X +>idY : { a: (y: Y) => Y; } +>a : (y: Y) => Y +>y : Y +>Y : Y +>Y : Y +>x : X +>X : X +>y : Y +>Y : Y +>X : X +>Y : Y + +const bottoxObj = { a: id }; +>bottoxObj : { a: (x: I) => I; } +>{ a: id } : { a: (x: I) => I; } +>a : (x: I) => I +>id : (x: I) => I + +const xyPair2: [number, string] = botox2(bottoxObj, bottoxObj)(3, 'str'); // ZZZ +>xyPair2 : [number, string] +>botox2(bottoxObj, bottoxObj)(3, 'str') : [{}, {}] +>botox2(bottoxObj, bottoxObj) : (x: {}, y: {}) => [{}, {}] +>botox2 : (idX: { a: (x: X) => X; }, idY: { a: (y: Y) => Y; }) => (x: X, y: Y) => [X, Y] +>bottoxObj : { a: (x: I) => I; } +>bottoxObj : { a: (x: I) => I; } +>3 : 3 +>'str' : "str" + +const xyPair3: [number, string] = botox2({ a: id }, { a: id })(3, 'str'); +>xyPair3 : [number, string] +>botox2({ a: id }, { a: id })(3, 'str') : [{}, {}] +>botox2({ a: id }, { a: id }) : (x: {}, y: {}) => [{}, {}] +>botox2 : (idX: { a: (x: X) => X; }, idY: { a: (y: Y) => Y; }) => (x: X, y: Y) => [X, Y] +>{ a: id } : { a: (x: I) => I; } +>a : (x: I) => I +>id : (x: I) => I +>{ a: id } : { a: (x: I) => I; } +>a : (x: I) => I +>id : (x: I) => I +>3 : 3 +>'str' : "str" + + +class GenericClass { +>GenericClass : GenericClass +>T : T + + payload: T; +>payload : T +>T : T +} + +var genericObject = new GenericClass<{ greeting: string }>(); +>genericObject : GenericClass<{ greeting: string; }> +>new GenericClass<{ greeting: string }>() : GenericClass<{ greeting: string; }> +>GenericClass : typeof GenericClass +>greeting : string + +function genericFunction(object: GenericClass, callback: (payload: T) => void) { +>genericFunction : (object: GenericClass, callback: (payload: T) => void) => void +>T : T +>object : GenericClass +>GenericClass : GenericClass +>T : T +>callback : (payload: T) => void +>payload : T +>T : T + + callback(object.payload); +>callback(object.payload) : void +>callback : (payload: T) => void +>object.payload : T +>object : GenericClass +>payload : T +} + +genericFunction(genericObject, ({greeting}) => { +>genericFunction(genericObject, ({greeting}) => { var s = greeting.toLocaleLowerCase(); // Greeting should be of type string}) : void +>genericFunction : (object: GenericClass, callback: (payload: T) => void) => void +>genericObject : GenericClass<{ greeting: string; }> +>({greeting}) => { var s = greeting.toLocaleLowerCase(); // Greeting should be of type string} : ({ greeting }: { greeting: string; }) => void +>greeting : string + + var s = greeting.toLocaleLowerCase(); // Greeting should be of type string +>s : string +>greeting.toLocaleLowerCase() : string +>greeting.toLocaleLowerCase : () => string +>greeting : string +>toLocaleLowerCase : () => string + +}); + +class Foo{ +>Foo : Foo +>T : T +>a : string +>b : number + + test: T; +>test : T +>T : T + + constructor(x: T){} +>x : T +>T : T +} + +var x = new Foo(true); // Should error +>x : any +>new Foo(true) : any +>Foo : typeof Foo +>true : true + +var y = new Foo({a: "test", b: 42}); // Should be OK +>y : Foo<{ a: string; b: number; }> +>new Foo({a: "test", b: 42}) : Foo<{ a: string; b: number; }> +>Foo : typeof Foo +>{a: "test", b: 42} : { a: string; b: number; } +>a : string +>"test" : "test" +>b : number +>42 : 42 + +var z: number = y.test.b; +>z : number +>y.test.b : number +>y.test : { a: string; b: number; } +>y : Foo<{ a: string; b: number; }> +>test : { a: string; b: number; } +>b : number + +declare function withFew(values: a[], haveFew: (values: a[]) => r, haveNone: (reason: string) => r): r; +>withFew : (values: a[], haveFew: (values: a[]) => r, haveNone: (reason: string) => r) => r +>a : a +>r : r +>values : a[] +>a : a +>haveFew : (values: a[]) => r +>values : a[] +>a : a +>r : r +>haveNone : (reason: string) => r +>reason : string +>r : r +>r : r + +function fail(message: string) : never { throw new Error(message); } +>fail : (message: string) => never +>message : string +>new Error(message) : Error +>Error : ErrorConstructor +>message : string + +const result: number[] = withFew([1, 2, 3], id, fail); // expected result is number[] +>result : number[] +>withFew([1, 2, 3], id, fail) : number[] +>withFew : (values: a[], haveFew: (values: a[]) => r, haveNone: (reason: string) => r) => r +>[1, 2, 3] : number[] +>1 : 1 +>2 : 2 +>3 : 3 +>id : (x: I) => I +>fail : (message: string) => never + +type List = { kind: 'nil' } +>List : List +>T : T +>kind : "nil" + + | { kind: 'cons', val: T, rest: List } +>kind : "cons" +>val : T +>T : T +>rest : List +>List : List +>T : T + +const Nil = { kind: 'nil' as 'nil' } +>Nil : { kind: "nil"; } +>{ kind: 'nil' as 'nil' } : { kind: "nil"; } +>kind : "nil" +>'nil' as 'nil' : "nil" +>'nil' : "nil" + +declare function cons(x: C, xs: List): List; +>cons : (x: C, xs: List) => List +>C : C +>x : C +>C : C +>xs : List +>List : List +>C : C +>List : List +>C : C + +declare function foldr(list: List, initial: A, f: (x: V, acc: A) => A): A; +>foldr : (list: List, initial: A, f: (x: V, acc: A) => A) => A +>V : V +>A : A +>list : List +>List : List +>V : V +>initial : A +>A : A +>f : (x: V, acc: A) => A +>x : V +>V : V +>acc : A +>A : A +>A : A +>A : A + +function concat(list: List>): List { +>concat : (list: List>) => List +>C : C +>list : List> +>List : List +>List : List +>C : C +>List : List +>C : C + + return foldr(list, Nil as List, append); +>foldr(list, Nil as List, append) : List +>foldr : (list: List, initial: A, f: (x: V, acc: A) => A) => A +>list : List> +>Nil as List : List +>Nil : { kind: "nil"; } +>List : List +>C : C +>append : (xs: List, ys: List) => List +} + +function append(xs: List, ys: List): List { +>append : (xs: List, ys: List) => List +>L : L +>xs : List +>List : List +>L : L +>ys : List +>List : List +>L : L +>List : List +>L : L + + return foldr(xs, ys, cons); +>foldr(xs, ys, cons) : List +>foldr : (list: List, initial: A, f: (x: V, acc: A) => A) => A +>xs : List +>ys : List +>cons : (x: C, xs: List) => List +} + +declare function zest(x: T): void; +>zest : (x: T) => void +>T : T +>x : T +>T : T + +zest(5); // should be number +>zest(5) : void +>zest : (x: T) => void +>5 : 5 + +function append2(xs: List, ys: List): List { +>append2 : (xs: List, ys: List) => List +>L : L +>xs : List +>List : List +>L : L +>ys : List +>List : List +>L : L +>List : List +>L : L + + return foldr(xs, ys, flip(fconst)); // ZZZ +>foldr(xs, ys, flip(fconst)) : List +>foldr : (list: List, initial: A, f: (x: V, acc: A) => A) => A +>xs : List +>ys : List +>flip(fconst) : (b: L, a: List) => List +>flip : (f: (a: A, b: B) => R) => (b: B, a: A) => R +>fconst : (x: X, y: Y) => X +} + +function append3(xs: List, ys: List) { +>append3 : (xs: List, ys: List) => List +>L : L +>xs : List +>List : List +>L : L +>ys : List +>List : List +>L : L + + return foldr(xs, ys, flip(fconst)); +>foldr(xs, ys, flip(fconst)) : List +>foldr : (list: List, initial: A, f: (x: V, acc: A) => A) => A +>xs : List +>ys : List +>flip(fconst) : (b: L, a: List) => List +>flip : (f: (a: A, b: B) => R) => (b: B, a: A) => R +>fconst : (x: X, y: Y) => X +} + +function append4(xs: List, ys: List) { +>append4 : (xs: List, ys: List) => List +>L : L +>xs : List +>List : List +>L : L +>ys : List +>List : List +>L : L + + return foldr(xs, ys, flip(flip(cons))); +>foldr(xs, ys, flip(flip(cons))) : List +>foldr : (list: List, initial: A, f: (x: V, acc: A) => A) => A +>xs : List +>ys : List +>flip(flip(cons)) : (b: L, a: List) => List +>flip : (f: (a: A, b: B) => R) => (b: B, a: A) => R +>flip(cons) : (b: List, a: L) => List +>flip : (f: (a: A, b: B) => R) => (b: B, a: A) => R +>cons : (x: C, xs: List) => List +} + +const infPowa: typeof append = append3; // ZZZ +>infPowa : (xs: List, ys: List) => List +>append : (xs: List, ys: List) => List +>append3 : (xs: List, ys: List) => List + +let jj = (n: T) => 'Error please?'; +>jj : (n: T) => string +>(n: T) => 'Error please?' : (n: T) => string +>T : T +>n : T +>T : T +>'Error please?' : "Error please?" + +let myFunc: (n: T) => T = jj; +>myFunc : (n: T) => T +>T : T +>n : T +>T : T +>T : T +>jj : (n: T) => string + +function foo(x: T): T { return x; } +>foo : (x: T) => T +>T : T +>Function : Function +>x : T +>T : T +>T : T +>x : T + +const r1 = foo(function (x: string) { return x; }); +>r1 : (x: string) => string +>foo(function (x: string) { return x; }) : (x: string) => string +>foo : (x: T) => T +>function (x: string) { return x; } : (x: string) => string +>x : string +>x : string + +const r2 = foo((x: string) => x); +>r2 : (x: string) => string +>foo((x: string) => x) : (x: string) => string +>foo : (x: T) => T +>(x: string) => x : (x: string) => string +>x : string +>x : string + +const r3 = foo(function (x: any) { return x; }); +>r3 : (x: any) => any +>foo(function (x: any) { return x; }) : (x: any) => any +>foo : (x: T) => T +>function (x: any) { return x; } : (x: any) => any +>x : any +>x : any + + +declare const cb1: { new (x: T): T }; +>cb1 : new (x: T) => T +>T : T +>x : T +>T : T +>T : T + +declare const cb2: { new(x: T): number; new(x: number): T; } +>cb2 : { new (x: T): number; new (x: number): T; } +>T : T +>x : T +>T : T +>T : T +>x : number +>T : T + +declare const cb3: { new(x: T): number; } +>cb3 : new (x: T) => number +>T : T +>x : T +>T : T + +declare const cb4: { new(x: number): T; } +>cb4 : new (x: number) => T +>T : T +>x : number +>T : T + +declare function foo7(x:T, cb: { new(x: T): string; new(x: T, y?: T): string }): void; +>foo7 : (x: T, cb: { new (x: T): string; new (x: T, y?: T | undefined): string; }) => void +>T : T +>x : T +>T : T +>cb : { new (x: T): string; new (x: T, y?: T | undefined): string; } +>x : T +>T : T +>x : T +>T : T +>y : T | undefined +>T : T + +foo7(1, cb1); // Should error (but won't error because type parameters erased when comparing more than one signature) +>foo7(1, cb1) : void +>foo7 : (x: T, cb: { new (x: T): string; new (x: T, y?: T | undefined): string; }) => void +>1 : 1 +>cb1 : new (x: T) => T + +foo7(1, cb2); +>foo7(1, cb2) : void +>foo7 : (x: T, cb: { new (x: T): string; new (x: T, y?: T | undefined): string; }) => void +>1 : 1 +>cb2 : { new (x: T): number; new (x: number): T; } + +foo7(1, cb3); +>foo7(1, cb3) : any +>foo7 : (x: T, cb: { new (x: T): string; new (x: T, y?: T | undefined): string; }) => void +>1 : 1 +>cb3 : new (x: T) => number + +foo7(1, cb4); +>foo7(1, cb4) : void +>foo7 : (x: T, cb: { new (x: T): string; new (x: T, y?: T | undefined): string; }) => void +>1 : 1 +>cb4 : new (x: number) => T + +declare function foo8(x:T, cb: { new(x: T): string; }): void; +>foo8 : (x: T, cb: new (x: T) => string) => void +>T : T +>x : T +>T : T +>cb : new (x: T) => string +>x : T +>T : T + +foo8(1, cb1); // Should error +>foo8(1, cb1) : any +>foo8 : (x: T, cb: new (x: T) => string) => void +>1 : 1 +>cb1 : new (x: T) => T + +foo8(1, cb2); +>foo8(1, cb2) : void +>foo8 : (x: T, cb: new (x: T) => string) => void +>1 : 1 +>cb2 : { new (x: T): number; new (x: number): T; } + +foo8(1, cb3); +>foo8(1, cb3) : any +>foo8 : (x: T, cb: new (x: T) => string) => void +>1 : 1 +>cb3 : new (x: T) => number + +foo8(1, cb4); +>foo8(1, cb4) : void +>foo8 : (x: T, cb: new (x: T) => string) => void +>1 : 1 +>cb4 : new (x: number) => T + +declare function foo9(x:T, cb: { new(x: T, y?: T): string }): void; +>foo9 : (x: T, cb: new (x: T, y?: T | undefined) => string) => void +>T : T +>x : T +>T : T +>cb : new (x: T, y?: T | undefined) => string +>x : T +>T : T +>y : T | undefined +>T : T + +foo9(1, cb1); // Should error +>foo9(1, cb1) : any +>foo9 : (x: T, cb: new (x: T, y?: T | undefined) => string) => void +>1 : 1 +>cb1 : new (x: T) => T + +foo9(1, cb2); +>foo9(1, cb2) : void +>foo9 : (x: T, cb: new (x: T, y?: T | undefined) => string) => void +>1 : 1 +>cb2 : { new (x: T): number; new (x: number): T; } + +foo9(1, cb3); +>foo9(1, cb3) : any +>foo9 : (x: T, cb: new (x: T, y?: T | undefined) => string) => void +>1 : 1 +>cb3 : new (x: T) => number + +foo9(1, cb4); +>foo9(1, cb4) : void +>foo9 : (x: T, cb: new (x: T, y?: T | undefined) => string) => void +>1 : 1 +>cb4 : new (x: number) => T + +function map(items: A[], f: (x: A) => B): B[]{ +>map : (items: A[], f: (x: A) => B) => B[] +>A : A +>B : B +>items : A[] +>A : A +>f : (x: A) => B +>x : A +>A : A +>B : B +>B : B + + return items.map(f); +>items.map(f) : B[] +>items.map : (callbackfn: (value: A, index: number, array: A[]) => U, thisArg?: any) => U[] +>items : A[] +>map : (callbackfn: (value: A, index: number, array: A[]) => U, thisArg?: any) => U[] +>f : (x: A) => B +} + +var v10: number[] = map([1, 2, 3], id); // Error if not number[] +>v10 : number[] +>map([1, 2, 3], id) : number[] +>map : (items: A[], f: (x: A) => B) => B[] +>[1, 2, 3] : number[] +>1 : 1 +>2 : 2 +>3 : 3 +>id : (x: I) => I + +function foo3(x: T, cb: (a: T) => U, y: U) { +>foo3 : (x: T, cb: (a: T) => U, y: U) => U +>T : T +>U : U +>x : T +>T : T +>cb : (a: T) => U +>a : T +>T : T +>U : U +>y : U +>U : U + + return cb(x); +>cb(x) : U +>cb : (a: T) => U +>x : T +} + +var r7 = foo3(1, (a: Z) => '', ''); // string +>r7 : string +>foo3(1, (a: Z) => '', '') : string +>foo3 : (x: T, cb: (a: T) => U, y: U) => U +>1 : 1 +>(a: Z) => '' : (a: Z) => string +>Z : Z +>a : Z +>Z : Z +>'' : "" +>'' : "" + +declare var a: { new (x: T): T; }; +>a : new (x: T) => T +>T : T +>x : T +>T : T +>T : T + +function foo2(x: T, cb: new(a: T) => U) { +>foo2 : (x: T, cb: new (a: T) => U) => U +>T : T +>U : U +>x : T +>T : T +>cb : new (a: T) => U +>a : T +>T : T +>U : U + + return new cb(x); +>new cb(x) : U +>cb : new (a: T) => U +>x : T +} + +var r4b = foo2(1, a); // number +>r4b : {} +>foo2(1, a) : {} +>foo2 : (x: T, cb: new (a: T) => U) => U +>1 : 1 +>a : new (x: T) => T + +function wf(n: N, f: (x: 5) => N): N { +>wf : (n: N, f: (x: 5) => N) => N +>N : N +>n : N +>N : N +>f : (x: 5) => N +>x : 5 +>N : N +>N : N + + return f(n); +>f(n) : N +>f : (x: 5) => N +>n : N +} +const wfr: 5 = wf(5, id); +>wfr : 5 +>wf(5, id) : 5 +>wf : (n: N, f: (x: 5) => N) => N +>5 : 5 +>id : (x: I) => I + +const wfr2 = wf(4, id); // error +>wfr2 : any +>wf(4, id) : any +>wf : (n: N, f: (x: 5) => N) => N +>4 : 4 +>id : (x: I) => I + +declare function flip(f: (a: A, b: B) => R): (b: B, a: A) => R; +>flip : (f: (a: A, b: B) => R) => (b: B, a: A) => R +>A : A +>B : B +>R : R +>f : (a: A, b: B) => R +>a : A +>A : A +>b : B +>B : B +>R : R +>b : B +>B : B +>a : A +>A : A +>R : R + +function id(x: I): I { +>id : (x: I) => I +>I : I +>x : I +>I : I +>I : I + + return x; +>x : I +} + +function fconst(x: X, y: Y): X { +>fconst : (x: X, y: Y) => X +>X : X +>Y : Y +>x : X +>X : X +>y : Y +>Y : Y +>X : X + + return x; +>x : X +} + +function addStr(x: number, y: string) { +>addStr : (x: number, y: string) => string +>x : number +>y : string + + return x + y; +>x + y : string +>x : number +>y : string +} + +function tagged(tag: T, value: Q): { tag: T, value: Q } { +>tagged : (tag: T, value: Q) => { tag: T; value: Q; } +>T : T +>Q : Q +>tag : T +>T : T +>value : Q +>Q : Q +>tag : T +>T : T +>value : Q +>Q : Q + + return { tag, value }; +>{ tag, value } : { tag: T; value: Q; } +>tag : T +>value : Q +} + +function fbound(tag: T, value: Q): { tag: T, value: Q } { +>fbound : (tag: T, value: Q) => { tag: T; value: Q; } +>T : T +>Q : Q +>Q : Q +>tag : T +>T : T +>value : Q +>Q : Q +>tag : T +>T : T +>value : Q +>Q : Q + + return { tag, value }; +>{ tag, value } : { tag: T; value: Q; } +>tag : T +>value : Q +} + +fbound(4, 4).tag; // 4 (better) or number +>fbound(4, 4).tag : number +>fbound(4, 4) : { tag: number; value: number; } +>fbound : (tag: T, value: Q) => { tag: T; value: Q; } +>4 : 4 +>4 : 4 +>tag : number + +flip(fbound)(4, 4) // OK +>flip(fbound)(4, 4) : { tag: {}; value: {}; } +>flip(fbound) : (b: {}, a: {}) => { tag: {}; value: {}; } +>flip : (f: (a: A, b: B) => R) => (b: B, a: A) => R +>fbound : (tag: T, value: Q) => { tag: T; value: Q; } +>4 : 4 +>4 : 4 + +fbound(4, "4"); // Error +>fbound(4, "4") : any +>fbound : (tag: T, value: Q) => { tag: T; value: Q; } +>4 : 4 +>"4" : "4" + +flip(fbound)("4", 4) // Error +>flip(fbound)("4", 4) : { tag: {}; value: {}; } +>flip(fbound) : (b: {}, a: {}) => { tag: {}; value: {}; } +>flip : (f: (a: A, b: B) => R) => (b: B, a: A) => R +>fbound : (tag: T, value: Q) => { tag: T; value: Q; } +>"4" : "4" +>4 : 4 + +function of2(one: a, two: b): [a, b] { +>of2 : (one: a, two: b) => [a, b] +>a : a +>b : b +>one : a +>a : a +>two : b +>b : b +>a : a +>b : b + + return [one, two]; +>[one, two] : [a, b] +>one : a +>two : b +} +const flipped = flip(of2); +>flipped : (b: {}, a: {}) => [{}, {}] +>flip(of2) : (b: {}, a: {}) => [{}, {}] +>flip : (f: (a: A, b: B) => R) => (b: B, a: A) => R +>of2 : (one: a, two: b) => [a, b] + +// it was working before +const f1 = flip(addStr); // (b: string, a: number) => string +>f1 : (b: string, a: number) => string +>flip(addStr) : (b: string, a: number) => string +>flip : (f: (a: A, b: B) => R) => (b: B, a: A) => R +>addStr : (x: number, y: string) => string + +const v1 = f1("hello", 3); +>v1 : string +>f1("hello", 3) : string +>f1 : (b: string, a: number) => string +>"hello" : "hello" +>3 : 3 + +const v2 = id(id)(3); // `3` +>v2 : 3 +>id(id)(3) : 3 +>id(id) : (x: I) => I +>id : (x: I) => I +>id : (x: I) => I +>3 : 3 + +// working now +const f2 = flip(id); // (b: {}, a: T): T +>f2 : (b: {}, a: {}) => {} +>flip(id) : (b: {}, a: {}) => {} +>flip : (f: (a: A, b: B) => R) => (b: B, a: A) => R +>id : (x: I) => I + +const f3 = flip(fconst); // (b: Y, a: X) => X +>f3 : (b: {}, a: {}) => {} +>flip(fconst) : (b: {}, a: {}) => {} +>flip : (f: (a: A, b: B) => R) => (b: B, a: A) => R +>fconst : (x: X, y: Y) => X + +const f4 = flip(tagged); // (b: Q, a: T) => { tag: T, value: Q } +>f4 : any +>flip(tagged) : any +>flip : (f: (a: A, b: B) => R) => (b: B, a: A) => R +>tagged : (tag: T, value: Q) => { tag: T; value: Q; } + +const v3 = f3(1, "qw") // `"qw"` +>v3 : {} +>f3(1, "qw") : {} +>f3 : (b: {}, a: {}) => {} +>1 : 1 +>"qw" : "qw" + +const v4 = f3([], {}) // `{}` +>v4 : {} +>f3([], {}) : {} +>f3 : (b: {}, a: {}) => {} +>[] : never[] +>{} : {} + +const v5 = f4(5, "hello"); // { tag: "hello", value: number } +>v5 : any +>f4(5, "hello") : any +>f4 : any +>5 : 5 +>"hello" : "hello" + +const v6 = f4(5, 5); // Error as expected +>v6 : any +>f4(5, 5) : any +>f4 : any +>5 : 5 +>5 : 5 + +declare function compose(f: (b: B) => C, g: (a: A) => B): (a: A) => C; +>compose : (f: (b: B) => C, g: (a: A) => B) => (a: A) => C +>A : A +>B : B +>C : C +>f : (b: B) => C +>b : B +>B : B +>C : C +>g : (a: A) => B +>a : A +>A : A +>B : B +>a : A +>A : A +>C : C + +declare const f: (x:number) => T; +>f : (x: number) => T +>T : T +>x : number +>T : T + +declare const g: (x:boolean) => number; +>g : (x: boolean) => number +>x : boolean + +const f5 = compose(f, g) // OUCH! this gets type `(a: boolean) => T` +>f5 : any +>compose(f, g) : any +>compose : (f: (b: B) => C, g: (a: A) => B) => (a: A) => C +>f : (x: number) => T +>g : (x: boolean) => number + +declare const g_2: (x: T) => boolean; +>g_2 : (x: T) => boolean +>T : T +>x : T +>T : T + +declare const f_2: (x: boolean) => number; +>f_2 : (x: boolean) => number +>x : boolean + +const f6 = compose(f_2, g_2) // (a: T) => number +>f6 : (a: {}) => number +>compose(f_2, g_2) : (a: {}) => number +>compose : (f: (b: B) => C, g: (a: A) => B) => (a: A) => C +>f_2 : (x: boolean) => number +>g_2 : (x: T) => boolean + +const f7 = compose(id, x => String(x)) // (a: {}) => string +>f7 : (a: {}) => {} +>compose(id, x => String(x)) : (a: {}) => {} +>compose : (f: (b: B) => C, g: (a: A) => B) => (a: A) => C +>id : (x: I) => I +>x => String(x) : (x: {}) => string +>x : {} +>String(x) : string +>String : StringConstructor +>x : {} + +declare function h(f: (x: number) => R): R; +>h : (f: (x: number) => R) => R +>R : R +>f : (x: number) => R +>x : number +>R : R +>R : R + +var z: number = h(id); +>z : number +>h(id) : number +>h : (f: (x: number) => R) => R +>id : (x: I) => I + +const arr: number[] = [1, 2, 3].map(id); +>arr : number[] +>[1, 2, 3].map(id) : number[] +>[1, 2, 3].map : (callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any) => U[] +>[1, 2, 3] : number[] +>1 : 1 +>2 : 2 +>3 : 3 +>map : (callbackfn: (value: number, index: number, array: number[]) => U, thisArg?: any) => U[] +>id : (x: I) => I + +declare const val1: string | undefined; +>val1 : string | undefined + +declare function cleanse(x: T|undefined): x is T; +>cleanse : (x: T | undefined) => x is T +>T : T +>x : T | undefined +>T : T +>x : any +>T : T + +cleanse(val1); +>cleanse(val1) : boolean +>cleanse : (x: T | undefined) => x is T +>val1 : string | undefined + +class MyClass +>MyClass : MyClass +{ + one(c: boolean){}; +>one : (c: boolean) => void +>c : boolean + + two(){}; +>two : () => void +} + +declare const test: PickPrototype; +>test : PickPrototype +>PickPrototype : PickPrototype +>MyClass : typeof MyClass + +type PickPrototype = { +>PickPrototype : PickPrototype +>T : T +>prototype : any +>K : K +>T : T + + [P in K]: T['prototype'][P]; +>P : P +>K : K +>T : T +>P : P +} + + +function wrap(innerFunc: (data: T) => any) { +>wrap : (innerFunc: (data: T) => any) => (data: T) => any +>T : T +>innerFunc : (data: T) => any +>data : T +>T : T + + return (data:T) => innerFunc(data); +>(data:T) => innerFunc(data) : (data: T) => any +>data : T +>T : T +>innerFunc(data) : any +>innerFunc : (data: T) => any +>data : T +} + +function inner(x:number) {}; +>inner : (x: number) => void +>x : number + +inner(2); +>inner(2) : void +>inner : (x: number) => void +>2 : 2 + +let func = wrap(inner); +>func : (data: number) => any +>wrap(inner) : (data: number) => any +>wrap : (innerFunc: (data: T) => any) => (data: T) => any +>inner : (x: number) => void + +func(2); +>func(2) : any +>func : (data: number) => any +>2 : 2 + + +declare function union(f: (a: A|B|C, b: A|B|C, c: A|B|C) => void): void; +>union : (f: (a: A | B | C, b: A | B | C, c: A | B | C) => void) => void +>A : A +>B : B +>C : C +>f : (a: A | B | C, b: A | B | C, c: A | B | C) => void +>a : A | B | C +>A : A +>B : B +>C : C +>b : A | B | C +>A : A +>B : B +>C : C +>c : A | B | C +>A : A +>B : B +>C : C + +union((x: X, y: Y, z: Z) => x) +>union((x: X, y: Y, z: Z) => x) : void +>union : (f: (a: A | B | C, b: A | B | C, c: A | B | C) => void) => void +>(x: X, y: Y, z: Z) => x : (x: X, y: Y, z: Z) => X +>X : X +>Y : Y +>Z : Z +>x : X +>X : X +>y : Y +>Y : Y +>z : Z +>Z : Z +>x : X + +declare function union2(f: (a: A, b: B, c: C) => void): void; +>union2 : (f: (a: A, b: B, c: C) => void) => void +>A : A +>B : B +>C : C +>f : (a: A, b: B, c: C) => void +>a : A +>A : A +>b : B +>B : B +>c : C +>C : C + +union2((x: X|Y|Z, y: X|Y|Z, z: X|Y|Z) => x); +>union2((x: X|Y|Z, y: X|Y|Z, z: X|Y|Z) => x) : void +>union2 : (f: (a: A, b: B, c: C) => void) => void +>(x: X|Y|Z, y: X|Y|Z, z: X|Y|Z) => x : (x: X | Y | Z, y: X | Y | Z, z: X | Y | Z) => X | Y | Z +>X : X +>Y : Y +>Z : Z +>x : X | Y | Z +>X : X +>Y : Y +>Z : Z +>y : X | Y | Z +>X : X +>Y : Y +>Z : Z +>z : X | Y | Z +>X : X +>Y : Y +>Z : Z +>x : X | Y | Z + +declare function union3(f: (a: A|string, b: A|number) => B): B; +>union3 : (f: (a: string | A, b: number | A) => B) => B +>A : A +>B : B +>f : (a: string | A, b: number | A) => B +>a : string | A +>A : A +>b : number | A +>A : A +>B : B +>B : B + +declare function uParam31(x: X|number, y: X|string): X; +>uParam31 : (x: number | X, y: string | X) => X +>X : X +>x : number | X +>X : X +>y : string | X +>X : X +>X : X + +declare function uParam32(x: number, y: number|string): void; +>uParam32 : (x: number, y: string | number) => void +>x : number +>y : string | number + +declare function uParam33(x: string, y: number|string): void; +>uParam33 : (x: string, y: string | number) => void +>x : string +>y : string | number + +union3(uParam31); // error; A,X = [number, string] +>union3(uParam31) : {} +>union3 : (f: (a: string | A, b: number | A) => B) => B +>uParam31 : (x: number | X, y: string | X) => X + +union3(uParam32); // error +>union3(uParam32) : any +>union3 : (f: (a: string | A, b: number | A) => B) => B +>uParam32 : (x: number, y: string | number) => void + +union3(uParam33); // OK; A = string; B = void +>union3(uParam33) : void +>union3 : (f: (a: string | A, b: number | A) => B) => B +>uParam33 : (x: string, y: string | number) => void + +declare function union4(f: (b: A|B) => C, a: A): C; +>union4 : (f: (b: A | B) => C, a: A) => C +>A : A +>B : B +>C : C +>f : (b: A | B) => C +>b : A | B +>A : A +>B : B +>C : C +>a : A +>A : A +>C : C + +declare function uParam41(y: number|string): void; +>uParam41 : (y: string | number) => void +>y : string | number + +declare function uParam42(y: number|X): X; +>uParam42 : (y: number | X) => X +>X : X +>y : number | X +>X : X +>X : X + +declare function uParam43(y: string|X): X; +>uParam43 : (y: string | X) => X +>X : X +>y : string | X +>X : X +>X : X + +union4(uParam41, 4); // A = number, B = string, C = void +>union4(uParam41, 4) : any +>union4 : (f: (b: A | B) => C, a: A) => C +>uParam41 : (y: string | number) => void +>4 : 4 + +union4(uParam42, 4); // A = number, B = X, C = X +>union4(uParam42, 4) : {} +>union4 : (f: (b: A | B) => C, a: A) => C +>uParam42 : (y: number | X) => X +>4 : 4 + +union4(uParam43, 4); // A = number, B = string, C = number +>union4(uParam43, 4) : {} +>union4 : (f: (b: A | B) => C, a: A) => C +>uParam43 : (y: string | X) => X +>4 : 4 + diff --git a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.errors.txt b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.errors.txt new file mode 100644 index 0000000000000..70cbe902d4adb --- /dev/null +++ b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.errors.txt @@ -0,0 +1,192 @@ +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(17,11): error TS2322: Type '(a2: {}) => {}' is not assignable to type '(u: U) => U'. + Type '{}' is not assignable to type 'U'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(19,11): error TS2322: Type '{}' is not assignable to type 'string'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(24,11): error TS2322: Type '(a2: {}) => {}[]' is not assignable to type '(u: U) => U[]'. + Type '{}[]' is not assignable to type 'U[]'. + Type '{}' is not assignable to type 'U'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(26,11): error TS2322: Type '{}[]' is not assignable to type 'string[]'. + Type '{}' is not assignable to type 'string'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(31,11): error TS2322: Type '(a2: {}) => {}[]' is not assignable to type '(u: U) => U[]'. + Type '{}[]' is not assignable to type 'U[]'. + Type '{}' is not assignable to type 'U'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(33,11): error TS2322: Type '{}[]' is not assignable to type 'string[]'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(38,11): error TS2322: Type '(a2: {}) => { boxed: {}[]; }' is not assignable to type '(u: U) => { boxed: U[]; }'. + Type '{ boxed: {}[]; }' is not assignable to type '{ boxed: U[]; }'. + Types of property 'boxed' are incompatible. + Type '{}[]' is not assignable to type 'U[]'. + Type '{}' is not assignable to type 'U'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(40,11): error TS2322: Type '{ boxed: {}[]; }' is not assignable to type '{ boxed: string[]; }'. + Types of property 'boxed' are incompatible. + Type '{}[]' is not assignable to type 'string[]'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(45,11): error TS2322: Type '(d2: {}) => [{}, { boxed: string; }]' is not assignable to type '(u: U) => [U, { boxed: string; }]'. + Type '[{}, { boxed: string; }]' is not assignable to type '[U, { boxed: string; }]'. + Type '{}' is not assignable to type 'U'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(47,11): error TS2322: Type '[{}, { boxed: string; }]' is not assignable to type '[number, { boxed: string; }]'. + Type '{}' is not assignable to type 'number'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(56,36): error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(b1: {}) => string'. + Types of parameters 'x' and 'b1' are incompatible. + Type '{}' is not assignable to type 'string'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(63,37): error TS2345: Argument of type '(x2: string) => string[]' is not assignable to parameter of type '(b1: {}) => string[]'. + Types of parameters 'x2' and 'b1' are incompatible. + Type '{}' is not assignable to type 'string'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(70,37): error TS2345: Argument of type '(x2: string) => string' is not assignable to parameter of type '(b1: {}[]) => string'. + Types of parameters 'x2' and 'b1' are incompatible. + Type '{}[]' is not assignable to type 'string'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(77,37): error TS2345: Argument of type '(x2: string) => { boxed: string; }' is not assignable to parameter of type '(b1: {}[]) => { boxed: string; }'. + Types of parameters 'x2' and 'b1' are incompatible. + Type '{}[]' is not assignable to type 'string'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(85,11): error TS2322: Type '(d2: {}) => [{}, { boxed: string; }]' is not assignable to type '(u: U) => [U, { boxed: string; }]'. + Type '[{}, { boxed: string; }]' is not assignable to type '[U, { boxed: string; }]'. + Type '{}' is not assignable to type 'U'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(87,11): error TS2322: Type '[{}, { boxed: string; }]' is not assignable to type '[number, { boxed: string; }]'. + Type '{}' is not assignable to type 'number'. + + +==== tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts (16 errors) ==== + export {} + + declare function identity1(f: (t: T) => U): (t2: T) => U + const id1 = identity1(x => x) + + + declare function identity2(f: (t: T) => U): (t2: T) => U + const id2 = identity2(x => x) + + + // compose is just something I put in to make sure the contextual types handle multiple signatures. + declare function compose(f: (d: D) => E, g: (e: E) => F): (d2: D) => [D, F]; + declare function compose(f: (a1: A) => B, g: (b1: B) => C): (a2: A) => C; + + { + let composed1 = compose(x => x, x2 => x2) + const expectedComposed1: (u: U) => U = composed1; + ~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '(a2: {}) => {}' is not assignable to type '(u: U) => U'. +!!! error TS2322: Type '{}' is not assignable to type 'U'. + const callComposed1 = composed1("test"); + const expectedCallComposed1 : string = callComposed1; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{}' is not assignable to type 'string'. + } + + { + let composed2 = compose(x => x, x2 => [x2]) + const expectedComposed2: (u: U) => U[] = composed2; + ~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '(a2: {}) => {}[]' is not assignable to type '(u: U) => U[]'. +!!! error TS2322: Type '{}[]' is not assignable to type 'U[]'. +!!! error TS2322: Type '{}' is not assignable to type 'U'. + const callComposed2 = composed2("test"); + const expectedCallComposed2: string[] = callComposed2; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{}[]' is not assignable to type 'string[]'. +!!! error TS2322: Type '{}' is not assignable to type 'string'. + } + + { + let composed3 = compose(x => [x], x2 => x2) + const expectedComposed3: (u: U) => U[] = composed3; + ~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '(a2: {}) => {}[]' is not assignable to type '(u: U) => U[]'. +!!! error TS2322: Type '{}[]' is not assignable to type 'U[]'. +!!! error TS2322: Type '{}' is not assignable to type 'U'. + const callComposed3 = composed3("test"); + const expectedCallComposed3 : string[] = callComposed3; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{}[]' is not assignable to type 'string[]'. + } + + { + let composed4 = compose(x => [x], x2 => ({ boxed: x2 })); + const expectedComposed4: (u: U) => {boxed: U[]} = composed4; + ~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '(a2: {}) => { boxed: {}[]; }' is not assignable to type '(u: U) => { boxed: U[]; }'. +!!! error TS2322: Type '{ boxed: {}[]; }' is not assignable to type '{ boxed: U[]; }'. +!!! error TS2322: Types of property 'boxed' are incompatible. +!!! error TS2322: Type '{}[]' is not assignable to type 'U[]'. +!!! error TS2322: Type '{}' is not assignable to type 'U'. + const callComposed4 = composed4("test"); + const expectedCallComposed4 : {boxed: string[]} = callComposed4; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '{ boxed: {}[]; }' is not assignable to type '{ boxed: string[]; }'. +!!! error TS2322: Types of property 'boxed' are incompatible. +!!! error TS2322: Type '{}[]' is not assignable to type 'string[]'. + } + + { + let composed5 = compose(x => "" + x, x2 => ({ boxed: x2 })); + const expectedComposed5: (u: U) => [U, {boxed: string}] = composed5; + ~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '(d2: {}) => [{}, { boxed: string; }]' is not assignable to type '(u: U) => [U, { boxed: string; }]'. +!!! error TS2322: Type '[{}, { boxed: string; }]' is not assignable to type '[U, { boxed: string; }]'. +!!! error TS2322: Type '{}' is not assignable to type 'U'. + const callComposed5 = composed5(123456); + const expectedCallComposed5 : [number, {boxed: string}] = callComposed5; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '[{}, { boxed: string; }]' is not assignable to type '[number, { boxed: string; }]'. +!!! error TS2322: Type '{}' is not assignable to type 'number'. + } + + + declare function composeReverse(g: (e: E) => F, f: (d: D) => E): (d2: D) => [D, F]; + declare function composeReverse(g: (b1: B) => C, f: (a1: A) => B): (a2: A) => C; + + + { + let composed1 = composeReverse(x => x, x2 => x2) + ~~~~~~ +!!! error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(b1: {}) => string'. +!!! error TS2345: Types of parameters 'x' and 'b1' are incompatible. +!!! error TS2345: Type '{}' is not assignable to type 'string'. + const expectedComposed1: (u: U) => U = composed1; + const callComposed1 = composed1("test"); + const expectedCallComposed1 : string = callComposed1; + } + + { + let composed2 = composeReverse( x2 => [x2], x => x) + ~~~~~~~~~~ +!!! error TS2345: Argument of type '(x2: string) => string[]' is not assignable to parameter of type '(b1: {}) => string[]'. +!!! error TS2345: Types of parameters 'x2' and 'b1' are incompatible. +!!! error TS2345: Type '{}' is not assignable to type 'string'. + const expectedComposed2: (u: U) => U[] = composed2; + const callComposed2 = composed2("test"); + const expectedCallComposed2: string[] = callComposed2; + } + + { + let composed3 = composeReverse( x2 => x2, x => [x]) + ~~~~~~~~ +!!! error TS2345: Argument of type '(x2: string) => string' is not assignable to parameter of type '(b1: {}[]) => string'. +!!! error TS2345: Types of parameters 'x2' and 'b1' are incompatible. +!!! error TS2345: Type '{}[]' is not assignable to type 'string'. + const expectedComposed3: (u: U) => U[] = composed3; + const callComposed3 = composed3("test"); + const expectedCallComposed3 : string[] = callComposed3; + } + + { + let composed4 = composeReverse( x2 => ({ boxed: x2 }), x => [x]); + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2345: Argument of type '(x2: string) => { boxed: string; }' is not assignable to parameter of type '(b1: {}[]) => { boxed: string; }'. +!!! error TS2345: Types of parameters 'x2' and 'b1' are incompatible. +!!! error TS2345: Type '{}[]' is not assignable to type 'string'. + const expectedComposed4: (u: U) => {boxed: U[]} = composed4; + const callComposed4 = composed4("test"); + const expectedCallComposed4 : {boxed: string[]} = callComposed4; + } + + { + let composed5 = composeReverse( x2 => ({ boxed: x2 }), x => "" + x); + const expectedComposed5: (u: U) => [U, {boxed: string}] = composed5; + ~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '(d2: {}) => [{}, { boxed: string; }]' is not assignable to type '(u: U) => [U, { boxed: string; }]'. +!!! error TS2322: Type '[{}, { boxed: string; }]' is not assignable to type '[U, { boxed: string; }]'. +!!! error TS2322: Type '{}' is not assignable to type 'U'. + const callComposed5 = composed5(123456); + const expectedCallComposed5 : [number, {boxed: string}] = callComposed5; + ~~~~~~~~~~~~~~~~~~~~~ +!!! error TS2322: Type '[{}, { boxed: string; }]' is not assignable to type '[number, { boxed: string; }]'. +!!! error TS2322: Type '{}' is not assignable to type 'number'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.js b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.js new file mode 100644 index 0000000000000..e9bbaf9f3fa87 --- /dev/null +++ b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.js @@ -0,0 +1,156 @@ +//// [inferringGenericFunctionsFromGenericFunctionsContexual.ts] +export {} + +declare function identity1(f: (t: T) => U): (t2: T) => U +const id1 = identity1(x => x) + + +declare function identity2(f: (t: T) => U): (t2: T) => U +const id2 = identity2(x => x) + + +// compose is just something I put in to make sure the contextual types handle multiple signatures. +declare function compose(f: (d: D) => E, g: (e: E) => F): (d2: D) => [D, F]; +declare function compose(f: (a1: A) => B, g: (b1: B) => C): (a2: A) => C; + +{ + let composed1 = compose(x => x, x2 => x2) + const expectedComposed1: (u: U) => U = composed1; + const callComposed1 = composed1("test"); + const expectedCallComposed1 : string = callComposed1; +} + +{ + let composed2 = compose(x => x, x2 => [x2]) + const expectedComposed2: (u: U) => U[] = composed2; + const callComposed2 = composed2("test"); + const expectedCallComposed2: string[] = callComposed2; +} + +{ + let composed3 = compose(x => [x], x2 => x2) + const expectedComposed3: (u: U) => U[] = composed3; + const callComposed3 = composed3("test"); + const expectedCallComposed3 : string[] = callComposed3; +} + +{ + let composed4 = compose(x => [x], x2 => ({ boxed: x2 })); + const expectedComposed4: (u: U) => {boxed: U[]} = composed4; + const callComposed4 = composed4("test"); + const expectedCallComposed4 : {boxed: string[]} = callComposed4; +} + +{ + let composed5 = compose(x => "" + x, x2 => ({ boxed: x2 })); + const expectedComposed5: (u: U) => [U, {boxed: string}] = composed5; + const callComposed5 = composed5(123456); + const expectedCallComposed5 : [number, {boxed: string}] = callComposed5; +} + + +declare function composeReverse(g: (e: E) => F, f: (d: D) => E): (d2: D) => [D, F]; +declare function composeReverse(g: (b1: B) => C, f: (a1: A) => B): (a2: A) => C; + + +{ + let composed1 = composeReverse(x => x, x2 => x2) + const expectedComposed1: (u: U) => U = composed1; + const callComposed1 = composed1("test"); + const expectedCallComposed1 : string = callComposed1; +} + +{ + let composed2 = composeReverse( x2 => [x2], x => x) + const expectedComposed2: (u: U) => U[] = composed2; + const callComposed2 = composed2("test"); + const expectedCallComposed2: string[] = callComposed2; +} + +{ + let composed3 = composeReverse( x2 => x2, x => [x]) + const expectedComposed3: (u: U) => U[] = composed3; + const callComposed3 = composed3("test"); + const expectedCallComposed3 : string[] = callComposed3; +} + +{ + let composed4 = composeReverse( x2 => ({ boxed: x2 }), x => [x]); + const expectedComposed4: (u: U) => {boxed: U[]} = composed4; + const callComposed4 = composed4("test"); + const expectedCallComposed4 : {boxed: string[]} = callComposed4; +} + +{ + let composed5 = composeReverse( x2 => ({ boxed: x2 }), x => "" + x); + const expectedComposed5: (u: U) => [U, {boxed: string}] = composed5; + const callComposed5 = composed5(123456); + const expectedCallComposed5 : [number, {boxed: string}] = callComposed5; +} + + +//// [inferringGenericFunctionsFromGenericFunctionsContexual.js] +"use strict"; +exports.__esModule = true; +var id1 = identity1(function (x) { return x; }); +var id2 = identity2(function (x) { return x; }); +{ + var composed1 = compose(function (x) { return x; }, function (x2) { return x2; }); + var expectedComposed1 = composed1; + var callComposed1 = composed1("test"); + var expectedCallComposed1 = callComposed1; +} +{ + var composed2 = compose(function (x) { return x; }, function (x2) { return [x2]; }); + var expectedComposed2 = composed2; + var callComposed2 = composed2("test"); + var expectedCallComposed2 = callComposed2; +} +{ + var composed3 = compose(function (x) { return [x]; }, function (x2) { return x2; }); + var expectedComposed3 = composed3; + var callComposed3 = composed3("test"); + var expectedCallComposed3 = callComposed3; +} +{ + var composed4 = compose(function (x) { return [x]; }, function (x2) { return ({ boxed: x2 }); }); + var expectedComposed4 = composed4; + var callComposed4 = composed4("test"); + var expectedCallComposed4 = callComposed4; +} +{ + var composed5 = compose(function (x) { return "" + x; }, function (x2) { return ({ boxed: x2 }); }); + var expectedComposed5 = composed5; + var callComposed5 = composed5(123456); + var expectedCallComposed5 = callComposed5; +} +{ + var composed1 = composeReverse(function (x) { return x; }, function (x2) { return x2; }); + var expectedComposed1 = composed1; + var callComposed1 = composed1("test"); + var expectedCallComposed1 = callComposed1; +} +{ + var composed2 = composeReverse(function (x2) { return [x2]; }, function (x) { return x; }); + var expectedComposed2 = composed2; + var callComposed2 = composed2("test"); + var expectedCallComposed2 = callComposed2; +} +{ + var composed3 = composeReverse(function (x2) { return x2; }, function (x) { return [x]; }); + var expectedComposed3 = composed3; + var callComposed3 = composed3("test"); + var expectedCallComposed3 = callComposed3; +} +{ + var composed4 = composeReverse(function (x2) { return ({ boxed: x2 }); }, function (x) { return [x]; }); + var expectedComposed4 = composed4; + var callComposed4 = composed4("test"); + var expectedCallComposed4 = callComposed4; +} +{ + var composed5 = composeReverse(function (x2) { return ({ boxed: x2 }); }, function (x) { return "" + x; }); + var expectedComposed5 = composed5; + var callComposed5 = composed5(123456); + var expectedCallComposed5 = callComposed5; +} diff --git a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.symbols b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.symbols new file mode 100644 index 0000000000000..0b3ff8a8cbe2d --- /dev/null +++ b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.symbols @@ -0,0 +1,386 @@ +=== tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts === +export {} + +declare function identity1(f: (t: T) => U): (t2: T) => U +>identity1 : Symbol(identity1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 0, 9)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 2, 27)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 2, 29)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 2, 33)) +>t : Symbol(t, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 2, 37)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 2, 27)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 2, 29)) +>t2 : Symbol(t2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 2, 51)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 2, 27)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 2, 29)) + +const id1 = identity1(x => x) +>id1 : Symbol(id1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 3, 5)) +>identity1 : Symbol(identity1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 0, 9)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 3, 22)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 3, 22)) + + +declare function identity2(f: (t: T) => U): (t2: T) => U +>identity2 : Symbol(identity2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 3, 29)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 6, 27)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 6, 44)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 6, 48)) +>t : Symbol(t, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 6, 52)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 6, 27)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 6, 44)) +>t2 : Symbol(t2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 6, 66)) +>T : Symbol(T, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 6, 27)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 6, 44)) + +const id2 = identity2(x => x) +>id2 : Symbol(id2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 7, 5)) +>identity2 : Symbol(identity2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 3, 29)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 7, 22)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 7, 22)) + + +// compose is just something I put in to make sure the contextual types handle multiple signatures. +declare function compose(f: (d: D) => E, g: (e: E) => F): (d2: D) => [D, F]; +>compose : Symbol(compose, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 7, 29), Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 100)) +>D : Symbol(D, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 25)) +>E : Symbol(E, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 27)) +>F : Symbol(F, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 45)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 49)) +>d : Symbol(d, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 53)) +>D : Symbol(D, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 25)) +>E : Symbol(E, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 27)) +>g : Symbol(g, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 64)) +>e : Symbol(e, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 69)) +>E : Symbol(E, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 27)) +>F : Symbol(F, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 45)) +>d2 : Symbol(d2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 83)) +>D : Symbol(D, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 25)) +>D : Symbol(D, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 25)) +>F : Symbol(F, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 45)) + +declare function compose(f: (a1: A) => B, g: (b1: B) => C): (a2: A) => C; +>compose : Symbol(compose, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 7, 29), Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 100)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 12, 25)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 12, 27)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 12, 30)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 12, 34)) +>a1 : Symbol(a1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 12, 38)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 12, 25)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 12, 27)) +>g : Symbol(g, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 12, 50)) +>b1 : Symbol(b1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 12, 55)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 12, 27)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 12, 30)) +>a2 : Symbol(a2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 12, 70)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 12, 25)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 12, 30)) + +{ + let composed1 = compose(x => x, x2 => x2) +>composed1 : Symbol(composed1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 15, 7)) +>compose : Symbol(compose, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 7, 29), Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 100)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 15, 28)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 15, 28)) +>x2 : Symbol(x2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 15, 35)) +>x2 : Symbol(x2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 15, 35)) + + const expectedComposed1: (u: U) => U = composed1; +>expectedComposed1 : Symbol(expectedComposed1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 16, 9)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 16, 30)) +>u : Symbol(u, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 16, 33)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 16, 30)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 16, 30)) +>composed1 : Symbol(composed1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 15, 7)) + + const callComposed1 = composed1("test"); +>callComposed1 : Symbol(callComposed1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 17, 9)) +>composed1 : Symbol(composed1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 15, 7)) + + const expectedCallComposed1 : string = callComposed1; +>expectedCallComposed1 : Symbol(expectedCallComposed1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 18, 9)) +>callComposed1 : Symbol(callComposed1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 17, 9)) +} + +{ + let composed2 = compose(x => x, x2 => [x2]) +>composed2 : Symbol(composed2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 22, 7)) +>compose : Symbol(compose, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 7, 29), Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 100)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 22, 28)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 22, 28)) +>x2 : Symbol(x2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 22, 35)) +>x2 : Symbol(x2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 22, 35)) + + const expectedComposed2: (u: U) => U[] = composed2; +>expectedComposed2 : Symbol(expectedComposed2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 23, 9)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 23, 30)) +>u : Symbol(u, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 23, 33)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 23, 30)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 23, 30)) +>composed2 : Symbol(composed2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 22, 7)) + + const callComposed2 = composed2("test"); +>callComposed2 : Symbol(callComposed2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 24, 9)) +>composed2 : Symbol(composed2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 22, 7)) + + const expectedCallComposed2: string[] = callComposed2; +>expectedCallComposed2 : Symbol(expectedCallComposed2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 25, 9)) +>callComposed2 : Symbol(callComposed2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 24, 9)) +} + +{ + let composed3 = compose(x => [x], x2 => x2) +>composed3 : Symbol(composed3, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 29, 7)) +>compose : Symbol(compose, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 7, 29), Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 100)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 29, 28)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 29, 28)) +>x2 : Symbol(x2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 29, 37)) +>x2 : Symbol(x2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 29, 37)) + + const expectedComposed3: (u: U) => U[] = composed3; +>expectedComposed3 : Symbol(expectedComposed3, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 30, 9)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 30, 30)) +>u : Symbol(u, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 30, 33)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 30, 30)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 30, 30)) +>composed3 : Symbol(composed3, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 29, 7)) + + const callComposed3 = composed3("test"); +>callComposed3 : Symbol(callComposed3, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 31, 9)) +>composed3 : Symbol(composed3, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 29, 7)) + + const expectedCallComposed3 : string[] = callComposed3; +>expectedCallComposed3 : Symbol(expectedCallComposed3, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 32, 9)) +>callComposed3 : Symbol(callComposed3, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 31, 9)) +} + +{ + let composed4 = compose(x => [x], x2 => ({ boxed: x2 })); +>composed4 : Symbol(composed4, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 36, 7)) +>compose : Symbol(compose, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 7, 29), Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 100)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 36, 28)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 36, 28)) +>x2 : Symbol(x2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 36, 37)) +>boxed : Symbol(boxed, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 36, 46)) +>x2 : Symbol(x2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 36, 37)) + + const expectedComposed4: (u: U) => {boxed: U[]} = composed4; +>expectedComposed4 : Symbol(expectedComposed4, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 37, 9)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 37, 30)) +>u : Symbol(u, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 37, 33)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 37, 30)) +>boxed : Symbol(boxed, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 37, 43)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 37, 30)) +>composed4 : Symbol(composed4, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 36, 7)) + + const callComposed4 = composed4("test"); +>callComposed4 : Symbol(callComposed4, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 38, 9)) +>composed4 : Symbol(composed4, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 36, 7)) + + const expectedCallComposed4 : {boxed: string[]} = callComposed4; +>expectedCallComposed4 : Symbol(expectedCallComposed4, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 39, 9)) +>boxed : Symbol(boxed, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 39, 35)) +>callComposed4 : Symbol(callComposed4, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 38, 9)) +} + +{ + let composed5 = compose(x => "" + x, x2 => ({ boxed: x2 })); +>composed5 : Symbol(composed5, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 43, 7)) +>compose : Symbol(compose, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 7, 29), Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 11, 100)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 43, 28)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 43, 28)) +>x2 : Symbol(x2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 43, 40)) +>boxed : Symbol(boxed, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 43, 49)) +>x2 : Symbol(x2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 43, 40)) + + const expectedComposed5: (u: U) => [U, {boxed: string}] = composed5; +>expectedComposed5 : Symbol(expectedComposed5, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 44, 9)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 44, 30)) +>u : Symbol(u, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 44, 33)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 44, 30)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 44, 30)) +>boxed : Symbol(boxed, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 44, 47)) +>composed5 : Symbol(composed5, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 43, 7)) + + const callComposed5 = composed5(123456); +>callComposed5 : Symbol(callComposed5, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 45, 9)) +>composed5 : Symbol(composed5, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 43, 7)) + + const expectedCallComposed5 : [number, {boxed: string}] = callComposed5; +>expectedCallComposed5 : Symbol(expectedCallComposed5, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 46, 9)) +>boxed : Symbol(boxed, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 46, 44)) +>callComposed5 : Symbol(callComposed5, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 45, 9)) +} + + +declare function composeReverse(g: (e: E) => F, f: (d: D) => E): (d2: D) => [D, F]; +>composeReverse : Symbol(composeReverse, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 47, 1), Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 107)) +>D : Symbol(D, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 32)) +>E : Symbol(E, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 34)) +>F : Symbol(F, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 52)) +>g : Symbol(g, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 56)) +>e : Symbol(e, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 60)) +>E : Symbol(E, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 34)) +>F : Symbol(F, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 52)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 71)) +>d : Symbol(d, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 76)) +>D : Symbol(D, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 32)) +>E : Symbol(E, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 34)) +>d2 : Symbol(d2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 90)) +>D : Symbol(D, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 32)) +>D : Symbol(D, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 32)) +>F : Symbol(F, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 52)) + +declare function composeReverse(g: (b1: B) => C, f: (a1: A) => B): (a2: A) => C; +>composeReverse : Symbol(composeReverse, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 47, 1), Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 107)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 51, 32)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 51, 34)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 51, 37)) +>g : Symbol(g, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 51, 41)) +>b1 : Symbol(b1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 51, 45)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 51, 34)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 51, 37)) +>f : Symbol(f, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 51, 57)) +>a1 : Symbol(a1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 51, 62)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 51, 32)) +>B : Symbol(B, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 51, 34)) +>a2 : Symbol(a2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 51, 77)) +>A : Symbol(A, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 51, 32)) +>C : Symbol(C, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 51, 37)) + + +{ + let composed1 = composeReverse(x => x, x2 => x2) +>composed1 : Symbol(composed1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 55, 7)) +>composeReverse : Symbol(composeReverse, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 47, 1), Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 107)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 55, 35)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 55, 35)) +>x2 : Symbol(x2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 55, 42)) +>x2 : Symbol(x2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 55, 42)) + + const expectedComposed1: (u: U) => U = composed1; +>expectedComposed1 : Symbol(expectedComposed1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 56, 9)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 56, 30)) +>u : Symbol(u, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 56, 33)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 56, 30)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 56, 30)) +>composed1 : Symbol(composed1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 55, 7)) + + const callComposed1 = composed1("test"); +>callComposed1 : Symbol(callComposed1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 57, 9)) +>composed1 : Symbol(composed1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 55, 7)) + + const expectedCallComposed1 : string = callComposed1; +>expectedCallComposed1 : Symbol(expectedCallComposed1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 58, 9)) +>callComposed1 : Symbol(callComposed1, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 57, 9)) +} + +{ + let composed2 = composeReverse( x2 => [x2], x => x) +>composed2 : Symbol(composed2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 62, 7)) +>composeReverse : Symbol(composeReverse, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 47, 1), Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 107)) +>x2 : Symbol(x2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 62, 35)) +>x2 : Symbol(x2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 62, 35)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 62, 47)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 62, 47)) + + const expectedComposed2: (u: U) => U[] = composed2; +>expectedComposed2 : Symbol(expectedComposed2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 63, 9)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 63, 30)) +>u : Symbol(u, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 63, 33)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 63, 30)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 63, 30)) +>composed2 : Symbol(composed2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 62, 7)) + + const callComposed2 = composed2("test"); +>callComposed2 : Symbol(callComposed2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 64, 9)) +>composed2 : Symbol(composed2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 62, 7)) + + const expectedCallComposed2: string[] = callComposed2; +>expectedCallComposed2 : Symbol(expectedCallComposed2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 65, 9)) +>callComposed2 : Symbol(callComposed2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 64, 9)) +} + +{ + let composed3 = composeReverse( x2 => x2, x => [x]) +>composed3 : Symbol(composed3, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 69, 7)) +>composeReverse : Symbol(composeReverse, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 47, 1), Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 107)) +>x2 : Symbol(x2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 69, 35)) +>x2 : Symbol(x2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 69, 35)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 69, 45)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 69, 45)) + + const expectedComposed3: (u: U) => U[] = composed3; +>expectedComposed3 : Symbol(expectedComposed3, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 70, 9)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 70, 30)) +>u : Symbol(u, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 70, 33)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 70, 30)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 70, 30)) +>composed3 : Symbol(composed3, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 69, 7)) + + const callComposed3 = composed3("test"); +>callComposed3 : Symbol(callComposed3, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 71, 9)) +>composed3 : Symbol(composed3, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 69, 7)) + + const expectedCallComposed3 : string[] = callComposed3; +>expectedCallComposed3 : Symbol(expectedCallComposed3, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 72, 9)) +>callComposed3 : Symbol(callComposed3, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 71, 9)) +} + +{ + let composed4 = composeReverse( x2 => ({ boxed: x2 }), x => [x]); +>composed4 : Symbol(composed4, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 76, 7)) +>composeReverse : Symbol(composeReverse, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 47, 1), Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 107)) +>x2 : Symbol(x2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 76, 35)) +>boxed : Symbol(boxed, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 76, 44)) +>x2 : Symbol(x2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 76, 35)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 76, 58)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 76, 58)) + + const expectedComposed4: (u: U) => {boxed: U[]} = composed4; +>expectedComposed4 : Symbol(expectedComposed4, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 77, 9)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 77, 30)) +>u : Symbol(u, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 77, 33)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 77, 30)) +>boxed : Symbol(boxed, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 77, 43)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 77, 30)) +>composed4 : Symbol(composed4, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 76, 7)) + + const callComposed4 = composed4("test"); +>callComposed4 : Symbol(callComposed4, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 78, 9)) +>composed4 : Symbol(composed4, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 76, 7)) + + const expectedCallComposed4 : {boxed: string[]} = callComposed4; +>expectedCallComposed4 : Symbol(expectedCallComposed4, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 79, 9)) +>boxed : Symbol(boxed, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 79, 35)) +>callComposed4 : Symbol(callComposed4, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 78, 9)) +} + +{ + let composed5 = composeReverse( x2 => ({ boxed: x2 }), x => "" + x); +>composed5 : Symbol(composed5, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 83, 7)) +>composeReverse : Symbol(composeReverse, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 47, 1), Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 50, 107)) +>x2 : Symbol(x2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 83, 35)) +>boxed : Symbol(boxed, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 83, 44)) +>x2 : Symbol(x2, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 83, 35)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 83, 58)) +>x : Symbol(x, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 83, 58)) + + const expectedComposed5: (u: U) => [U, {boxed: string}] = composed5; +>expectedComposed5 : Symbol(expectedComposed5, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 84, 9)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 84, 30)) +>u : Symbol(u, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 84, 33)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 84, 30)) +>U : Symbol(U, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 84, 30)) +>boxed : Symbol(boxed, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 84, 47)) +>composed5 : Symbol(composed5, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 83, 7)) + + const callComposed5 = composed5(123456); +>callComposed5 : Symbol(callComposed5, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 85, 9)) +>composed5 : Symbol(composed5, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 83, 7)) + + const expectedCallComposed5 : [number, {boxed: string}] = callComposed5; +>expectedCallComposed5 : Symbol(expectedCallComposed5, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 86, 9)) +>boxed : Symbol(boxed, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 86, 44)) +>callComposed5 : Symbol(callComposed5, Decl(inferringGenericFunctionsFromGenericFunctionsContexual.ts, 85, 9)) +} + diff --git a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.types b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.types new file mode 100644 index 0000000000000..84217860e7ee3 --- /dev/null +++ b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.types @@ -0,0 +1,458 @@ +=== tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts === +export {} + +declare function identity1(f: (t: T) => U): (t2: T) => U +>identity1 : (f: (t: T) => U) => (t2: T) => U +>T : T +>U : U +>f : (t: T) => U +>t : T +>T : T +>U : U +>t2 : T +>T : T +>U : U + +const id1 = identity1(x => x) +>id1 : (t2: {}) => {} +>identity1(x => x) : (t2: {}) => {} +>identity1 : (f: (t: T) => U) => (t2: T) => U +>x => x : (x: {}) => {} +>x : {} +>x : {} + + +declare function identity2(f: (t: T) => U): (t2: T) => U +>identity2 : (f: (t: T) => U) => (t2: T) => U +>T : T +>U : U +>f : (t: T) => U +>t : T +>T : T +>U : U +>t2 : T +>T : T +>U : U + +const id2 = identity2(x => x) +>id2 : (t2: number) => number +>identity2(x => x) : (t2: number) => number +>identity2 : (f: (t: T) => U) => (t2: T) => U +>x => x : (x: number) => number +>x : number +>x : number + + +// compose is just something I put in to make sure the contextual types handle multiple signatures. +declare function compose(f: (d: D) => E, g: (e: E) => F): (d2: D) => [D, F]; +>compose : { (f: (d: D) => E, g: (e: E) => F): (d2: D) => [D, F]; (f: (a1: A) => B, g: (b1: B) => C): (a2: A) => C; } +>D : D +>E : E +>F : F +>f : (d: D) => E +>d : D +>D : D +>E : E +>g : (e: E) => F +>e : E +>E : E +>F : F +>d2 : D +>D : D +>D : D +>F : F + +declare function compose(f: (a1: A) => B, g: (b1: B) => C): (a2: A) => C; +>compose : { (f: (d: D) => E, g: (e: E) => F): (d2: D) => [D, F]; (f: (a1: A) => B, g: (b1: B) => C): (a2: A) => C; } +>A : A +>B : B +>C : C +>f : (a1: A) => B +>a1 : A +>A : A +>B : B +>g : (b1: B) => C +>b1 : B +>B : B +>C : C +>a2 : A +>A : A +>C : C + +{ + let composed1 = compose(x => x, x2 => x2) +>composed1 : (a2: {}) => {} +>compose(x => x, x2 => x2) : (a2: {}) => {} +>compose : { (f: (d: D) => E, g: (e: E) => F): (d2: D) => [D, F]; (f: (a1: A) => B, g: (b1: B) => C): (a2: A) => C; } +>x => x : (x: {}) => {} +>x : {} +>x : {} +>x2 => x2 : (x2: {}) => {} +>x2 : {} +>x2 : {} + + const expectedComposed1: (u: U) => U = composed1; +>expectedComposed1 : (u: U) => U +>U : U +>u : U +>U : U +>U : U +>composed1 : (a2: {}) => {} + + const callComposed1 = composed1("test"); +>callComposed1 : {} +>composed1("test") : {} +>composed1 : (a2: {}) => {} +>"test" : "test" + + const expectedCallComposed1 : string = callComposed1; +>expectedCallComposed1 : string +>callComposed1 : {} +} + +{ + let composed2 = compose(x => x, x2 => [x2]) +>composed2 : (a2: {}) => {}[] +>compose(x => x, x2 => [x2]) : (a2: {}) => {}[] +>compose : { (f: (d: D) => E, g: (e: E) => F): (d2: D) => [D, F]; (f: (a1: A) => B, g: (b1: B) => C): (a2: A) => C; } +>x => x : (x: {}) => {} +>x : {} +>x : {} +>x2 => [x2] : (x2: {}) => {}[] +>x2 : {} +>[x2] : {}[] +>x2 : {} + + const expectedComposed2: (u: U) => U[] = composed2; +>expectedComposed2 : (u: U) => U[] +>U : U +>u : U +>U : U +>U : U +>composed2 : (a2: {}) => {}[] + + const callComposed2 = composed2("test"); +>callComposed2 : {}[] +>composed2("test") : {}[] +>composed2 : (a2: {}) => {}[] +>"test" : "test" + + const expectedCallComposed2: string[] = callComposed2; +>expectedCallComposed2 : string[] +>callComposed2 : {}[] +} + +{ + let composed3 = compose(x => [x], x2 => x2) +>composed3 : (a2: {}) => {}[] +>compose(x => [x], x2 => x2) : (a2: {}) => {}[] +>compose : { (f: (d: D) => E, g: (e: E) => F): (d2: D) => [D, F]; (f: (a1: A) => B, g: (b1: B) => C): (a2: A) => C; } +>x => [x] : (x: {}) => {}[] +>x : {} +>[x] : {}[] +>x : {} +>x2 => x2 : (x2: {}[]) => {}[] +>x2 : {}[] +>x2 : {}[] + + const expectedComposed3: (u: U) => U[] = composed3; +>expectedComposed3 : (u: U) => U[] +>U : U +>u : U +>U : U +>U : U +>composed3 : (a2: {}) => {}[] + + const callComposed3 = composed3("test"); +>callComposed3 : {}[] +>composed3("test") : {}[] +>composed3 : (a2: {}) => {}[] +>"test" : "test" + + const expectedCallComposed3 : string[] = callComposed3; +>expectedCallComposed3 : string[] +>callComposed3 : {}[] +} + +{ + let composed4 = compose(x => [x], x2 => ({ boxed: x2 })); +>composed4 : (a2: {}) => { boxed: {}[]; } +>compose(x => [x], x2 => ({ boxed: x2 })) : (a2: {}) => { boxed: {}[]; } +>compose : { (f: (d: D) => E, g: (e: E) => F): (d2: D) => [D, F]; (f: (a1: A) => B, g: (b1: B) => C): (a2: A) => C; } +>x => [x] : (x: {}) => {}[] +>x : {} +>[x] : {}[] +>x : {} +>x2 => ({ boxed: x2 }) : (x2: {}[]) => { boxed: {}[]; } +>x2 : {}[] +>({ boxed: x2 }) : { boxed: {}[]; } +>{ boxed: x2 } : { boxed: {}[]; } +>boxed : {}[] +>x2 : {}[] + + const expectedComposed4: (u: U) => {boxed: U[]} = composed4; +>expectedComposed4 : (u: U) => { boxed: U[]; } +>U : U +>u : U +>U : U +>boxed : U[] +>U : U +>composed4 : (a2: {}) => { boxed: {}[]; } + + const callComposed4 = composed4("test"); +>callComposed4 : { boxed: {}[]; } +>composed4("test") : { boxed: {}[]; } +>composed4 : (a2: {}) => { boxed: {}[]; } +>"test" : "test" + + const expectedCallComposed4 : {boxed: string[]} = callComposed4; +>expectedCallComposed4 : { boxed: string[]; } +>boxed : string[] +>callComposed4 : { boxed: {}[]; } +} + +{ + let composed5 = compose(x => "" + x, x2 => ({ boxed: x2 })); +>composed5 : (d2: {}) => [{}, { boxed: string; }] +>compose(x => "" + x, x2 => ({ boxed: x2 })) : (d2: {}) => [{}, { boxed: string; }] +>compose : { (f: (d: D) => E, g: (e: E) => F): (d2: D) => [D, F]; (f: (a1: A) => B, g: (b1: B) => C): (a2: A) => C; } +>x => "" + x : (x: {}) => string +>x : {} +>"" + x : string +>"" : "" +>x : {} +>x2 => ({ boxed: x2 }) : (x2: string) => { boxed: string; } +>x2 : string +>({ boxed: x2 }) : { boxed: string; } +>{ boxed: x2 } : { boxed: string; } +>boxed : string +>x2 : string + + const expectedComposed5: (u: U) => [U, {boxed: string}] = composed5; +>expectedComposed5 : (u: U) => [U, { boxed: string; }] +>U : U +>u : U +>U : U +>U : U +>boxed : string +>composed5 : (d2: {}) => [{}, { boxed: string; }] + + const callComposed5 = composed5(123456); +>callComposed5 : [{}, { boxed: string; }] +>composed5(123456) : [{}, { boxed: string; }] +>composed5 : (d2: {}) => [{}, { boxed: string; }] +>123456 : 123456 + + const expectedCallComposed5 : [number, {boxed: string}] = callComposed5; +>expectedCallComposed5 : [number, { boxed: string; }] +>boxed : string +>callComposed5 : [{}, { boxed: string; }] +} + + +declare function composeReverse(g: (e: E) => F, f: (d: D) => E): (d2: D) => [D, F]; +>composeReverse : { (g: (e: E) => F, f: (d: D) => E): (d2: D) => [D, F]; (g: (b1: B) => C, f: (a1: A) => B): (a2: A) => C; } +>D : D +>E : E +>F : F +>g : (e: E) => F +>e : E +>E : E +>F : F +>f : (d: D) => E +>d : D +>D : D +>E : E +>d2 : D +>D : D +>D : D +>F : F + +declare function composeReverse(g: (b1: B) => C, f: (a1: A) => B): (a2: A) => C; +>composeReverse : { (g: (e: E) => F, f: (d: D) => E): (d2: D) => [D, F]; (g: (b1: B) => C, f: (a1: A) => B): (a2: A) => C; } +>A : A +>B : B +>C : C +>g : (b1: B) => C +>b1 : B +>B : B +>C : C +>f : (a1: A) => B +>a1 : A +>A : A +>B : B +>a2 : A +>A : A +>C : C + + +{ + let composed1 = composeReverse(x => x, x2 => x2) +>composed1 : any +>composeReverse(x => x, x2 => x2) : any +>composeReverse : { (g: (e: E) => F, f: (d: D) => E): (d2: D) => [D, F]; (g: (b1: B) => C, f: (a1: A) => B): (a2: A) => C; } +>x => x : (x: string) => string +>x : string +>x : string +>x2 => x2 : (x2: {}) => {} +>x2 : {} +>x2 : {} + + const expectedComposed1: (u: U) => U = composed1; +>expectedComposed1 : (u: U) => U +>U : U +>u : U +>U : U +>U : U +>composed1 : any + + const callComposed1 = composed1("test"); +>callComposed1 : any +>composed1("test") : any +>composed1 : any +>"test" : "test" + + const expectedCallComposed1 : string = callComposed1; +>expectedCallComposed1 : string +>callComposed1 : any +} + +{ + let composed2 = composeReverse( x2 => [x2], x => x) +>composed2 : any +>composeReverse( x2 => [x2], x => x) : any +>composeReverse : { (g: (e: E) => F, f: (d: D) => E): (d2: D) => [D, F]; (g: (b1: B) => C, f: (a1: A) => B): (a2: A) => C; } +>x2 => [x2] : (x2: string) => string[] +>x2 : string +>[x2] : string[] +>x2 : string +>x => x : (x: {}) => {} +>x : {} +>x : {} + + const expectedComposed2: (u: U) => U[] = composed2; +>expectedComposed2 : (u: U) => U[] +>U : U +>u : U +>U : U +>U : U +>composed2 : any + + const callComposed2 = composed2("test"); +>callComposed2 : any +>composed2("test") : any +>composed2 : any +>"test" : "test" + + const expectedCallComposed2: string[] = callComposed2; +>expectedCallComposed2 : string[] +>callComposed2 : any +} + +{ + let composed3 = composeReverse( x2 => x2, x => [x]) +>composed3 : any +>composeReverse( x2 => x2, x => [x]) : any +>composeReverse : { (g: (e: E) => F, f: (d: D) => E): (d2: D) => [D, F]; (g: (b1: B) => C, f: (a1: A) => B): (a2: A) => C; } +>x2 => x2 : (x2: string) => string +>x2 : string +>x2 : string +>x => [x] : (x: {}) => {}[] +>x : {} +>[x] : {}[] +>x : {} + + const expectedComposed3: (u: U) => U[] = composed3; +>expectedComposed3 : (u: U) => U[] +>U : U +>u : U +>U : U +>U : U +>composed3 : any + + const callComposed3 = composed3("test"); +>callComposed3 : any +>composed3("test") : any +>composed3 : any +>"test" : "test" + + const expectedCallComposed3 : string[] = callComposed3; +>expectedCallComposed3 : string[] +>callComposed3 : any +} + +{ + let composed4 = composeReverse( x2 => ({ boxed: x2 }), x => [x]); +>composed4 : any +>composeReverse( x2 => ({ boxed: x2 }), x => [x]) : any +>composeReverse : { (g: (e: E) => F, f: (d: D) => E): (d2: D) => [D, F]; (g: (b1: B) => C, f: (a1: A) => B): (a2: A) => C; } +>x2 => ({ boxed: x2 }) : (x2: string) => { boxed: string; } +>x2 : string +>({ boxed: x2 }) : { boxed: string; } +>{ boxed: x2 } : { boxed: string; } +>boxed : string +>x2 : string +>x => [x] : (x: {}) => {}[] +>x : {} +>[x] : {}[] +>x : {} + + const expectedComposed4: (u: U) => {boxed: U[]} = composed4; +>expectedComposed4 : (u: U) => { boxed: U[]; } +>U : U +>u : U +>U : U +>boxed : U[] +>U : U +>composed4 : any + + const callComposed4 = composed4("test"); +>callComposed4 : any +>composed4("test") : any +>composed4 : any +>"test" : "test" + + const expectedCallComposed4 : {boxed: string[]} = callComposed4; +>expectedCallComposed4 : { boxed: string[]; } +>boxed : string[] +>callComposed4 : any +} + +{ + let composed5 = composeReverse( x2 => ({ boxed: x2 }), x => "" + x); +>composed5 : (d2: {}) => [{}, { boxed: string; }] +>composeReverse( x2 => ({ boxed: x2 }), x => "" + x) : (d2: {}) => [{}, { boxed: string; }] +>composeReverse : { (g: (e: E) => F, f: (d: D) => E): (d2: D) => [D, F]; (g: (b1: B) => C, f: (a1: A) => B): (a2: A) => C; } +>x2 => ({ boxed: x2 }) : (x2: string) => { boxed: string; } +>x2 : string +>({ boxed: x2 }) : { boxed: string; } +>{ boxed: x2 } : { boxed: string; } +>boxed : string +>x2 : string +>x => "" + x : (x: {}) => string +>x : {} +>"" + x : string +>"" : "" +>x : {} + + const expectedComposed5: (u: U) => [U, {boxed: string}] = composed5; +>expectedComposed5 : (u: U) => [U, { boxed: string; }] +>U : U +>u : U +>U : U +>U : U +>boxed : string +>composed5 : (d2: {}) => [{}, { boxed: string; }] + + const callComposed5 = composed5(123456); +>callComposed5 : [{}, { boxed: string; }] +>composed5(123456) : [{}, { boxed: string; }] +>composed5 : (d2: {}) => [{}, { boxed: string; }] +>123456 : 123456 + + const expectedCallComposed5 : [number, {boxed: string}] = callComposed5; +>expectedCallComposed5 : [number, { boxed: string; }] +>boxed : string +>callComposed5 : [{}, { boxed: string; }] +} + diff --git a/tests/cases/compiler/genericTypeParameterEquivalence2strict.ts b/tests/cases/compiler/genericTypeParameterEquivalence2strict.ts new file mode 100644 index 0000000000000..60ae3952d3ef8 --- /dev/null +++ b/tests/cases/compiler/genericTypeParameterEquivalence2strict.ts @@ -0,0 +1,67 @@ +// @strict: true + +// compose :: (b->c) -> (a->b) -> (a->c) +function compose(f: (b: B) => C, g: (a:A) => B): (a:A) => C { + return function (a:A) : C { + return f(g.apply(null, a)); + }; +} + +// forEach :: [a] -> (a -> ()) -> () +function forEach(list: A[], f: (a: A, n?: number) => void ): void { + for (var i = 0; i < list.length; ++i) { + f(list[i], i); + } +} + +// filter :: (a->bool) -> [a] -> [a] +function filter(f: (a: A) => boolean, ar: A[]): A[] { + var ret: A[] = []; + forEach(ar, (el) => { + if (f(el)) { + ret.push(el); + } + } ); + + return ret; +} + +// length :: [a] -> Num +function length2(ar: A[]): number { + return ar.length; +} + +// curry1 :: ((a,b)->c) -> (a->(b->c)) +function curry1(f: (a: A, b: B) => C): (ax: A) => (bx: B) => C { + return function (ay: A) { + return function (by: B) { + return f(ay, by); + }; + }; +} + +var cfilter = curry1(filter); + +declare function strBool(str: string): boolean +const filterer = cfilter(strBool); +const expectFilterer: (a: string[]) => string[] = filterer; + +const filtered = filterer(["hello"]); +const expectFiltered: string[] = filtered; + +// compose :: (b->c) -> (a->b) -> (a->c) +// length :: [a] -> Num +// cfilter :: {} -> {} -> [{}] +// pred :: a -> Bool +// cfilter(pred) :: {} -> [{}] +// length2 :: [a] -> Num +// countWhere :: (a -> Bool) -> [a] -> Num + +function countWhere_1(pred: (a: A) => boolean): (a: A[]) => number { + return compose(length2, cfilter(pred)); +} + +function countWhere_2(pred: (a: A) => boolean): (a: A[]) => number { + var where = cfilter(pred); + return compose(length2, where); +} \ No newline at end of file diff --git a/tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions.ts b/tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions.ts new file mode 100644 index 0000000000000..eb57b28e3fcff --- /dev/null +++ b/tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions.ts @@ -0,0 +1,34 @@ +// @strict: true +export {} + + +// example from https://github.com/Microsoft/TypeScript/issues/9366 + +function flip(f: (a: a, b: b) => c): (b: b, a: a) => c { + return (b: b, a: a) => f(a, b); +} +function zip(x: T, y: U): [T, U] { + return [x, y]; +} + +const flipped = flip(zip); +var expected: (y: U, x: T) => [T, U] = flipped; + +const actualCallResult = flipped("test", 1234) +const expectedResult: [number, string] = actualCallResult; + + + + +// from https://github.com/Microsoft/TypeScript/issues/16414 + +declare function compose(f: (x: A) => B, g: (y: B) => C): (x: A) => C; +declare function box(x: T): { value: T }; +declare function list(x: U): U[]; + +const composed = compose(list, box); +const expectedComposed: (u: U) => { value: U[] } = composed; + + +const callComposed = composed("test"); +const expectedCallComposed: { value: string[] } = callComposed; \ No newline at end of file diff --git a/tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts b/tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts new file mode 100644 index 0000000000000..40ecb5238a7e4 --- /dev/null +++ b/tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts @@ -0,0 +1,368 @@ +// @strict: true +export {} + +// Borrowed from @gcnew at https://gist.github.com/gcnew/ad833bfa376e4b70fc50a780e3b2d883 + +interface Collection { + length: number; + add(x: T): void; + remove(x: T): boolean; +} +interface Combinators { + map(c: Collection, f: (x: T) => U): Collection; + map(c: Collection, f: (x: T) => any): Collection; + forEach(c: Collection, f: (x: T) => Date): void; +} + +declare var _: Combinators; +declare var c2: Collection; + +var rf1 = (x: number) => { return x.toFixed() }; +var r1a = _.map(c2, (x) => { return x.toFixed() }); +var r5 = _.forEach(c2, rf1); // Should error +var r6 = _.forEach(c2, (x) => { return x.toFixed() }); // Should error +declare const zipWith: (a: T[], b: S[], f: (x: T) => (y: S) => U) => U[]; +declare const pair: (x: T) => (y: S) => { x: T; y: S; } +const zr = zipWith([1, 2], ['a', 'b'], pair); + +declare function lego1(x: A, l: List, y: A): A; +declare function lego2(f: (l: List, x: D, y: D) => D): void; +lego2(lego1); + +declare function bombastic(f: (x: string, y: number) => R): R; +declare function bombastic2(f: (x: string, y: number) => string): void; +declare function bombastic3(f: (x: string, y: number, z: R) => R): R; +declare function okay(f: (x: 1, y: number) => R): R; +declare function transitive(x: T, f: (x: T) => T): void; + +bombastic(id2); // Should be an error T = [string, number] +bombastic2(id2); // Should be an error T = [string, number] +bombastic(id2); // should be an error because bombastic's callback is (x: string, y: number) => R and the explicit type argument here is setting `R`, not setting T and U from id2 +declare function id3(x: T, y: U, z: V): V; +bombastic3(id3); // Should be error +bombastic3(id3); // Should be error because of reason from bombastic(id2) +okay(id2); +transitive(1, withNum); +transitive('1', withNum); + +declare function occurs(f: (x: number, xs: List) => R): R; +occurs(id2); // should be error + +declare function f15(x: T, f: (x: T) => T): void; +declare function g15(n: number): number; +f15(5, g15); + +interface J { + [s: string]: T; +} + +declare function g1(obj: J): T; +const rg1: string = g1({ p: "" }); + +declare function forEachChild(node: Node, cbNode: (node: Node) => T | undefined, cbNodeArray?: (nodes: NodeArray) => T | undefined): T | undefined; + +class Node { + _node: any; + + forEachChild(cbNode: (node: Node) => C, cbNodeArray?: (nodes: NodeArray) => C): C { + return forEachChild(this, cbNode, cbNodeArray); + } +} + +interface NodeBrand { _nodearray: any } +class Declaration extends Node { _declarationBrand: any; } +class ParameterDeclaration extends Declaration { _paramdecl: any; } +interface Arr { + concat(...items: T[][]): T[]; + concat(...items: (T | T[])[]): T[]; +} +interface NodeArray extends Arr, NodeBrand { } + +declare function indexOf(hay: Arr, needle: T): number; +declare const fps: NodeArray; +declare const node: Node; + +indexOf(fps, node); + +function selfRef(n: number, callback: (n: number) => T): T { + return selfRef(n, callback); +} + +class A { x: any; } +class B extends A { y: any; } +class Chain { + then(cb: (x: T) => S): Chain { + return null!; + } +} + +declare const chainB: Chain; +chainB.then(b => new A); + + +declare function f16(f: (x: number) => 4): void; +declare function g16(x: number): number; +f16(g16); + + +declare function trans(f: (x: T) => string): number; +// TODO: these should all be noImplicitAny / destructuring erros +trans(({a}) => a); +trans(([b,c]) => 'foo'); +trans(({d: [e,f]}) => 'foo'); +trans(([{g},{h}]) => 'foo'); +trans(({a, b = 10}) => a); + +declare function idCreator(f: (x: T|undefined) => T): T; +const icn: number = idCreator(_ => 5); // ZZZ +declare function bar(x: T, y: U, cb: (x: T, y: U) => V): V; +// having a second type parameter extend the first should prevent it from inferring a "string | number" union type from (x: string, y: number) => R +declare function id2(x: T, y: U): U; +var b2 = bar(1, "one", id2); // Should be error + + +declare function id2OneTypeParam(x: T, y: T): T; +var b4 = bar(1, "one", id2OneTypeParam); // Should be number | string + + + +declare function withNum(x: N): N; +declare function withString(f: (x: S) => S): void; +declare function useString(f: (x: string) => string): void; + +withString(withNum); // Error +useString(withNum); // Error +declare function f10(x: T): T; +declare function f10(x: T, y: number): T; + +const a10: string[] = ["a", "b"]; +const b10 = a10.map(f10); + +declare function botox(idX: (x: X) => X, idY: (y: Y) => Y): (x: X, y: Y) => [X, Y]; +const xyPair: [number, string] = botox(id, id)(3, 'str'); +const testPair: { x: number, y: string } = pair(3)('str'); + +declare function botox2(idX: { a: (x: X) => X }, idY: { a: (y: Y) => Y }): (x: X, y: Y) => [X, Y]; + +const bottoxObj = { a: id }; +const xyPair2: [number, string] = botox2(bottoxObj, bottoxObj)(3, 'str'); // ZZZ +const xyPair3: [number, string] = botox2({ a: id }, { a: id })(3, 'str'); + + +class GenericClass { + payload: T; +} + +var genericObject = new GenericClass<{ greeting: string }>(); + +function genericFunction(object: GenericClass, callback: (payload: T) => void) { + callback(object.payload); +} + +genericFunction(genericObject, ({greeting}) => { + var s = greeting.toLocaleLowerCase(); // Greeting should be of type string +}); + +class Foo{ + test: T; + constructor(x: T){} +} + +var x = new Foo(true); // Should error +var y = new Foo({a: "test", b: 42}); // Should be OK +var z: number = y.test.b; + +declare function withFew(values: a[], haveFew: (values: a[]) => r, haveNone: (reason: string) => r): r; +function fail(message: string) : never { throw new Error(message); } +const result: number[] = withFew([1, 2, 3], id, fail); // expected result is number[] +type List = { kind: 'nil' } + | { kind: 'cons', val: T, rest: List } + +const Nil = { kind: 'nil' as 'nil' } + +declare function cons(x: C, xs: List): List; +declare function foldr(list: List, initial: A, f: (x: V, acc: A) => A): A; + +function concat(list: List>): List { + return foldr(list, Nil as List, append); +} + +function append(xs: List, ys: List): List { + return foldr(xs, ys, cons); +} + +declare function zest(x: T): void; +zest(5); // should be number +function append2(xs: List, ys: List): List { + return foldr(xs, ys, flip(fconst)); // ZZZ +} + +function append3(xs: List, ys: List) { + return foldr(xs, ys, flip(fconst)); +} + +function append4(xs: List, ys: List) { + return foldr(xs, ys, flip(flip(cons))); +} + +const infPowa: typeof append = append3; // ZZZ +let jj = (n: T) => 'Error please?'; +let myFunc: (n: T) => T = jj; + +function foo(x: T): T { return x; } +const r1 = foo(function (x: string) { return x; }); +const r2 = foo((x: string) => x); +const r3 = foo(function (x: any) { return x; }); + + +declare const cb1: { new (x: T): T }; +declare const cb2: { new(x: T): number; new(x: number): T; } +declare const cb3: { new(x: T): number; } +declare const cb4: { new(x: number): T; } +declare function foo7(x:T, cb: { new(x: T): string; new(x: T, y?: T): string }): void; + +foo7(1, cb1); // Should error (but won't error because type parameters erased when comparing more than one signature) +foo7(1, cb2); +foo7(1, cb3); +foo7(1, cb4); + +declare function foo8(x:T, cb: { new(x: T): string; }): void; +foo8(1, cb1); // Should error +foo8(1, cb2); +foo8(1, cb3); +foo8(1, cb4); + +declare function foo9(x:T, cb: { new(x: T, y?: T): string }): void; +foo9(1, cb1); // Should error +foo9(1, cb2); +foo9(1, cb3); +foo9(1, cb4); + +function map(items: A[], f: (x: A) => B): B[]{ + return items.map(f); +} + +var v10: number[] = map([1, 2, 3], id); // Error if not number[] +function foo3(x: T, cb: (a: T) => U, y: U) { + return cb(x); +} + +var r7 = foo3(1, (a: Z) => '', ''); // string +declare var a: { new (x: T): T; }; +function foo2(x: T, cb: new(a: T) => U) { + return new cb(x); +} + +var r4b = foo2(1, a); // number + +function wf(n: N, f: (x: 5) => N): N { + return f(n); +} +const wfr: 5 = wf(5, id); +const wfr2 = wf(4, id); // error +declare function flip(f: (a: A, b: B) => R): (b: B, a: A) => R; + +function id(x: I): I { + return x; +} + +function fconst(x: X, y: Y): X { + return x; +} + +function addStr(x: number, y: string) { + return x + y; +} + +function tagged(tag: T, value: Q): { tag: T, value: Q } { + return { tag, value }; +} + +function fbound(tag: T, value: Q): { tag: T, value: Q } { + return { tag, value }; +} + +fbound(4, 4).tag; // 4 (better) or number +flip(fbound)(4, 4) // OK +fbound(4, "4"); // Error +flip(fbound)("4", 4) // Error + +function of2(one: a, two: b): [a, b] { + return [one, two]; +} +const flipped = flip(of2); + +// it was working before +const f1 = flip(addStr); // (b: string, a: number) => string +const v1 = f1("hello", 3); +const v2 = id(id)(3); // `3` +// working now +const f2 = flip(id); // (b: {}, a: T): T +const f3 = flip(fconst); // (b: Y, a: X) => X +const f4 = flip(tagged); // (b: Q, a: T) => { tag: T, value: Q } +const v3 = f3(1, "qw") // `"qw"` +const v4 = f3([], {}) // `{}` +const v5 = f4(5, "hello"); // { tag: "hello", value: number } +const v6 = f4(5, 5); // Error as expected +declare function compose(f: (b: B) => C, g: (a: A) => B): (a: A) => C; + +declare const f: (x:number) => T; +declare const g: (x:boolean) => number; +const f5 = compose(f, g) // OUCH! this gets type `(a: boolean) => T` +declare const g_2: (x: T) => boolean; +declare const f_2: (x: boolean) => number; +const f6 = compose(f_2, g_2) // (a: T) => number +const f7 = compose(id, x => String(x)) // (a: {}) => string +declare function h(f: (x: number) => R): R; +var z: number = h(id); + +const arr: number[] = [1, 2, 3].map(id); + +declare const val1: string | undefined; +declare function cleanse(x: T|undefined): x is T; + +cleanse(val1); + +class MyClass +{ + one(c: boolean){}; + two(){}; +} + +declare const test: PickPrototype; +type PickPrototype = { + [P in K]: T['prototype'][P]; +} + + +function wrap(innerFunc: (data: T) => any) { + return (data:T) => innerFunc(data); +} + +function inner(x:number) {}; +inner(2); + +let func = wrap(inner); +func(2); + + +declare function union(f: (a: A|B|C, b: A|B|C, c: A|B|C) => void): void; +union((x: X, y: Y, z: Z) => x) + +declare function union2(f: (a: A, b: B, c: C) => void): void; +union2((x: X|Y|Z, y: X|Y|Z, z: X|Y|Z) => x); + +declare function union3(f: (a: A|string, b: A|number) => B): B; +declare function uParam31(x: X|number, y: X|string): X; +declare function uParam32(x: number, y: number|string): void; +declare function uParam33(x: string, y: number|string): void; +union3(uParam31); // error; A,X = [number, string] +union3(uParam32); // error +union3(uParam33); // OK; A = string; B = void +declare function union4(f: (b: A|B) => C, a: A): C; +declare function uParam41(y: number|string): void; +declare function uParam42(y: number|X): X; +declare function uParam43(y: string|X): X; +union4(uParam41, 4); // A = number, B = string, C = void +union4(uParam42, 4); // A = number, B = X, C = X +union4(uParam43, 4); // A = number, B = string, C = number \ No newline at end of file diff --git a/tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts b/tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts new file mode 100644 index 0000000000000..c94afeed0fcea --- /dev/null +++ b/tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts @@ -0,0 +1,89 @@ +// @strict: true +export {} + +declare function identity1(f: (t: T) => U): (t2: T) => U +const id1 = identity1(x => x) + + +declare function identity2(f: (t: T) => U): (t2: T) => U +const id2 = identity2(x => x) + + +// compose is just something I put in to make sure the contextual types handle multiple signatures. +declare function compose(f: (d: D) => E, g: (e: E) => F): (d2: D) => [D, F]; +declare function compose(f: (a1: A) => B, g: (b1: B) => C): (a2: A) => C; + +{ + let composed1 = compose(x => x, x2 => x2) + const expectedComposed1: (u: U) => U = composed1; + const callComposed1 = composed1("test"); + const expectedCallComposed1 : string = callComposed1; +} + +{ + let composed2 = compose(x => x, x2 => [x2]) + const expectedComposed2: (u: U) => U[] = composed2; + const callComposed2 = composed2("test"); + const expectedCallComposed2: string[] = callComposed2; +} + +{ + let composed3 = compose(x => [x], x2 => x2) + const expectedComposed3: (u: U) => U[] = composed3; + const callComposed3 = composed3("test"); + const expectedCallComposed3 : string[] = callComposed3; +} + +{ + let composed4 = compose(x => [x], x2 => ({ boxed: x2 })); + const expectedComposed4: (u: U) => {boxed: U[]} = composed4; + const callComposed4 = composed4("test"); + const expectedCallComposed4 : {boxed: string[]} = callComposed4; +} + +{ + let composed5 = compose(x => "" + x, x2 => ({ boxed: x2 })); + const expectedComposed5: (u: U) => [U, {boxed: string}] = composed5; + const callComposed5 = composed5(123456); + const expectedCallComposed5 : [number, {boxed: string}] = callComposed5; +} + + +declare function composeReverse(g: (e: E) => F, f: (d: D) => E): (d2: D) => [D, F]; +declare function composeReverse(g: (b1: B) => C, f: (a1: A) => B): (a2: A) => C; + + +{ + let composed1 = composeReverse(x => x, x2 => x2) + const expectedComposed1: (u: U) => U = composed1; + const callComposed1 = composed1("test"); + const expectedCallComposed1 : string = callComposed1; +} + +{ + let composed2 = composeReverse( x2 => [x2], x => x) + const expectedComposed2: (u: U) => U[] = composed2; + const callComposed2 = composed2("test"); + const expectedCallComposed2: string[] = callComposed2; +} + +{ + let composed3 = composeReverse( x2 => x2, x => [x]) + const expectedComposed3: (u: U) => U[] = composed3; + const callComposed3 = composed3("test"); + const expectedCallComposed3 : string[] = callComposed3; +} + +{ + let composed4 = composeReverse( x2 => ({ boxed: x2 }), x => [x]); + const expectedComposed4: (u: U) => {boxed: U[]} = composed4; + const callComposed4 = composed4("test"); + const expectedCallComposed4 : {boxed: string[]} = callComposed4; +} + +{ + let composed5 = composeReverse( x2 => ({ boxed: x2 }), x => "" + x); + const expectedComposed5: (u: U) => [U, {boxed: string}] = composed5; + const callComposed5 = composed5(123456); + const expectedCallComposed5 : [number, {boxed: string}] = callComposed5; +} From 664c4d93e499950ae3ff5603abb4175182338ac5 Mon Sep 17 00:00:00 2001 From: Kevin Donnelly Date: Sat, 2 Jun 2018 11:24:59 -0500 Subject: [PATCH 2/4] Changes to allow propagating type parameters with no inferences. A summary of the bigger pieces I can think of: * When strictFunctionTypes is true if there are no inferences for a type parameter then the type parameter itself will be returned instead of defaulting to `{}`. After chooseOverload returns a successful signature, the return type of that signature is checked and if the return type is a function type with a single call signature then any free type parameters found in that call signature are converted to type parameters for the call signature. If the return type is not a call signature then any free type parameters are converted to `{}` at that point. * inferFromSignatures will instantiate the source in the context of the target if the source signature has type parameters and strictFunctionTypes is true. * StrictFunctionTypes is required in both of the above cases because of errors that pop up otherwise when there are not contravariant inferences. * Seemingly free type parameters that are outerTypeParameters of the call being inferred are ignored instead of being erased. This is to avoid erasing type parameters when calling functions inside the body of a generic function. * When choosing an overload with multiple signatures that have contextually typed arguments, any contextual types that are assigned are reset when trying a new candidate. Updated baselines will be committed in the following commit. --- src/compiler/checker.ts | 375 ++++++++++++++++++++++++++++++++++------ src/compiler/types.ts | 14 ++ 2 files changed, 332 insertions(+), 57 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index dc43faac4357c..0a67e586c9d48 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -5269,13 +5269,18 @@ namespace ts { case SyntaxKind.JSDocCallbackTag: case SyntaxKind.MappedType: case SyntaxKind.ConditionalType: - const outerTypeParameters = getOuterTypeParameters(node, includeThisTypes); + let outerTypeParameters = getOuterTypeParameters(node, includeThisTypes); if (node.kind === SyntaxKind.MappedType) { return append(outerTypeParameters, getDeclaredTypeOfTypeParameter(getSymbolOfNode((node).typeParameter))); } else if (node.kind === SyntaxKind.ConditionalType) { return concatenate(outerTypeParameters, getInferTypeParameters(node)); } + else if ((node.kind === SyntaxKind.FunctionExpression || node.kind === SyntaxKind.ArrowFunction) && node.contextualTypeParameters) { + for (const tp of node.contextualTypeParameters) { + outerTypeParameters = appendIfUnique(outerTypeParameters, tp); + } + } const outerAndOwnTypeParameters = appendTypeParameters(outerTypeParameters, getEffectiveTypeParameterDeclarations(node)); const thisType = includeThisTypes && (node.kind === SyntaxKind.ClassDeclaration || node.kind === SyntaxKind.ClassExpression || node.kind === SyntaxKind.InterfaceDeclaration) && @@ -9018,12 +9023,12 @@ namespace ts { const isDeferred = root.isDistributive && maybeTypeOfKind(checkType, TypeFlags.Instantiable); let combinedMapper: TypeMapper | undefined; if (root.inferTypeParameters) { - const context = createInferenceContext(root.inferTypeParameters, /*signature*/ undefined, InferenceFlags.None); + const context = createInferenceContext(root.inferTypeParameters, /*signature*/ undefined, InferenceFlags.AlwaysDefault); if (!isDeferred) { // We don't want inferences from constraints as they may cause us to eagerly resolve the // conditional type instead of deferring resolution. Also, we always want strict function // types rules (i.e. proper contravariance) for inferences. - inferTypes(context.inferences, checkType, extendsType, InferencePriority.NoConstraints | InferencePriority.AlwaysStrict); + inferTypes(context.inferences, checkType, extendsType, InferencePriority.NoConstraints | InferencePriority.AlwaysStrict, /*eraseSignatures*/ true); } combinedMapper = combineTypeMappers(mapper, context); } @@ -9707,9 +9712,11 @@ namespace ts { return result; } - function getAnonymousTypeInstantiation(type: AnonymousType, mapper: TypeMapper) { - const target = type.objectFlags & ObjectFlags.Instantiated ? type.target! : type; - const { symbol } = target; + function getTypeParametersForAnonymousType(type: AnonymousType): TypeParameter[] { + if (!mightReferenceTypeParameter(type)) { + return emptyArray; + } + const { symbol } = type; const links = getSymbolLinks(symbol); let typeParameters = links.outerTypeParameters; if (!typeParameters) { @@ -9727,21 +9734,30 @@ namespace ts { } } } + const ownTypeParameters = declaration.contextualTypeParameters; let outerTypeParameters = getOuterTypeParameters(declaration, /*includeThisTypes*/ true); if (isJavaScriptConstructor(declaration)) { const templateTagParameters = getTypeParametersFromDeclaration(declaration as DeclarationWithTypeParameters); outerTypeParameters = addRange(outerTypeParameters, templateTagParameters); } - typeParameters = outerTypeParameters || emptyArray; - typeParameters = symbol.flags & SymbolFlags.TypeLiteral && !target.aliasTypeArguments ? + typeParameters = concatenate(outerTypeParameters, ownTypeParameters) || emptyArray; + typeParameters = symbol.flags & SymbolFlags.TypeLiteral && !type.aliasTypeArguments ? filter(typeParameters, tp => isTypeParameterPossiblyReferenced(tp, declaration)) : typeParameters; links.outerTypeParameters = typeParameters; if (typeParameters.length) { links.instantiations = createMap(); - links.instantiations.set(getTypeListId(typeParameters), target); + links.instantiations.set(getTypeListId(typeParameters), type); } } + return typeParameters; + } + + function getAnonymousTypeInstantiation(type: AnonymousType, mapper: TypeMapper) { + const target = type.objectFlags & ObjectFlags.Instantiated ? type.target! : type; + const { symbol } = target; + const links = getSymbolLinks(symbol); + const typeParameters = getTypeParametersForAnonymousType(target); if (typeParameters.length) { // We are instantiating an anonymous type that has one or more type parameters in scope. Apply the // mapper to the type parameters to produce the effective list of type arguments, and compute the @@ -9753,6 +9769,7 @@ namespace ts { if (!result) { const newMapper = createTypeMapper(typeParameters, typeArguments); result = target.objectFlags & ObjectFlags.Mapped ? instantiateMappedType(target, newMapper) : instantiateAnonymousType(target, newMapper); + (result).typeArguments = typeArguments; links.instantiations!.set(id, result); } return result; @@ -9760,6 +9777,63 @@ namespace ts { return type; } + function isTypeParameter(type: Type): type is TypeParameter { + return !!(type.flags & TypeFlags.TypeParameter); + } + + function isAnonymousType(type: Type): type is AnonymousType { + return !!(getObjectFlags(type) & ObjectFlags.Anonymous); + } + + function isTypeReference(type: Type): type is TypeReference { + return !!(getObjectFlags(type) & ObjectFlags.Reference); + } + + function isUnionOrIntersection(type: Type): type is UnionOrIntersectionType { + return !!(type.flags & TypeFlags.UnionOrIntersection); + } + + function getFreeTypeParameters(type: Type): TypeParameter[] { + if (!type.freeTypeParameters) { + if (isTypeParameter(type)) { + type.freeTypeParameters = type.isThisType ? emptyArray : [type]; + return type.freeTypeParameters; + } + const typesToCheck = isTypeReference(type) ? type.typeArguments || emptyArray : + isAnonymousType(type) ? type.typeArguments || getTypeParametersForAnonymousType(type) : + isUnionOrIntersection(type) ? type.types : emptyArray; + + let freeTypeParameters: TypeParameter[] | undefined; + for (const t of typesToCheck) { + for (const tp of getFreeTypeParameters(t)) { + freeTypeParameters = appendIfUnique(freeTypeParameters, tp); + } + } + type.freeTypeParameters = freeTypeParameters || emptyArray; + } + return type.freeTypeParameters; + } + + function handleFreeTypeParameters(type: Type, typeParametersToIgnore: TypeParameter[] | undefined, isJs: boolean): Type { + const freeTypeParameters = getFreeTypeParameters(type); + const parametersToHandle = filter(freeTypeParameters, tp => !contains(typeParametersToIgnore, tp)); + if (parametersToHandle.length) { + const singleCallSignature = getSingleCallSignature(type); + if (singleCallSignature) { + const clonedExtraTypeParameters = map(parametersToHandle, cloneTypeParameter); + const mapper = createTypeMapper(parametersToHandle, clonedExtraTypeParameters); + const newSignature = instantiateSignature(singleCallSignature, mapper); + newSignature.typeParameters = concatenate(newSignature.typeParameters, clonedExtraTypeParameters); + return getOrCreateTypeFromSignature(newSignature); + } + else { + const mapper = createTypeMapper(parametersToHandle, map(parametersToHandle, _ => getDefaultTypeArgumentType(isJs))); + return instantiateType(type, mapper); + } + } + return type; + } + function maybeTypeParameterReference(node: Node) { return !(node.kind === SyntaxKind.QualifiedName || node.parent.kind === SyntaxKind.TypeReference && (node.parent).typeArguments && node === (node.parent).typeName); @@ -9863,6 +9937,10 @@ namespace ts { return getConditionalType(root, mapper); } + function mightReferenceTypeParameter(type: AnonymousType) { + return type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) && type.symbol.declarations; + } + function instantiateType(type: Type, mapper: TypeMapper | undefined): Type; function instantiateType(type: Type | undefined, mapper: TypeMapper | undefined): Type | undefined; function instantiateType(type: Type | undefined, mapper: TypeMapper | undefined): Type | undefined { @@ -9875,8 +9953,7 @@ namespace ts { // If the anonymous type originates in a declaration of a function, method, class, or // interface, in an object type literal, or in an object literal expression, we may need // to instantiate the type because it might reference a type parameter. - return type.symbol && type.symbol.flags & (SymbolFlags.Function | SymbolFlags.Method | SymbolFlags.Class | SymbolFlags.TypeLiteral | SymbolFlags.ObjectLiteral) && type.symbol.declarations ? - getAnonymousTypeInstantiation(type, mapper) : type; + return mightReferenceTypeParameter(type) ? getAnonymousTypeInstantiation(type, mapper) : type; } if ((type).objectFlags & ObjectFlags.Mapped) { return getAnonymousTypeInstantiation(type, mapper); @@ -9922,6 +9999,62 @@ namespace ts { return info && createIndexInfo(instantiateType(info.type, mapper), info.isReadonly, info.declaration); } + + function visitContextSensitive(node: MaybeContextSensitive, visitor: (node: Node) => void): void { + if (!isContextSensitive(node)) { + return; + } + switch (node.kind) { + case SyntaxKind.FunctionExpression: + case SyntaxKind.ArrowFunction: + case SyntaxKind.MethodDeclaration: + if (isContextSensitiveFunctionLikeDeclaration(node)) { + visitor(node); + } + return; + case SyntaxKind.ObjectLiteralExpression: + return forEach((node).properties, n => visitContextSensitive(n, visitor)); + case SyntaxKind.ArrayLiteralExpression: + return forEach((node).elements, n => visitContextSensitive(n, visitor)); + case SyntaxKind.ConditionalExpression: + visitContextSensitive((node).whenTrue, visitor); + visitContextSensitive((node).whenFalse, visitor); + return; + case SyntaxKind.BinaryExpression: + if ((node).operatorToken.kind === SyntaxKind.BarBarToken) { + visitContextSensitive((node).left, visitor); + visitContextSensitive((node).right, visitor); + } + return; + case SyntaxKind.PropertyAssignment: + visitContextSensitive((node).initializer, visitor); + return; + case SyntaxKind.ParenthesizedExpression: + visitContextSensitive((node).expression, visitor); + return; + case SyntaxKind.JsxAttributes: + return forEach((node).properties, n => visitContextSensitive(n, visitor)); + case SyntaxKind.JsxAttribute: { + // If there is no initializer, JSX attribute has a boolean value of true which is not context sensitive. + const { initializer } = node as JsxAttribute; + if (!!initializer) { + visitContextSensitive(initializer, visitor); + } + return; + } + case SyntaxKind.JsxExpression: { + // It is possible to that node.expression is undefined (e.g
) + const { expression } = node as JsxExpression; + if (!!expression) { + visitContextSensitive(expression, visitor); + } + return; + } + } + return; + } + + // Returns true if the given expression contains (at any level of nesting) a function or arrow expression // that is subject to contextual typing. function isContextSensitive(node: Expression | MethodDeclaration | ObjectLiteralElementLike | JsxAttributeLike): boolean { @@ -12362,7 +12495,18 @@ namespace ts { for (let i = 0; i < inferences.length; i++) { if (t === inferences[i].typeParameter) { inferences[i].isFixed = true; - return getInferredType(context, i); + const inference = getInferredType(context, i); + + if (inferences[i].inferredType === inferences[i].typeParameter) { + inferences[i].inferredType = undefined; + } + + if (!inferences[i].inferredType) { + inferences[i].isFixed = false; + return context.useEmptyObjectForNoInference ? emptyObjectType : inference; + } + + return inference; } } return t; @@ -12377,7 +12521,7 @@ namespace ts { inferredType: undefined, priority: undefined, topLevel: true, - isFixed: false + isFixed: false, }; } @@ -12389,7 +12533,7 @@ namespace ts { inferredType: inference.inferredType, priority: inference.priority, topLevel: inference.topLevel, - isFixed: inference.isFixed + isFixed: inference.isFixed, }; } @@ -12509,27 +12653,16 @@ namespace ts { emptyObjectType; } - function inferTypes(inferences: InferenceInfo[], originalSource: Type, originalTarget: Type, priority: InferencePriority = 0) { + function inferTypes(inferences: InferenceInfo[], originalSource: Type, originalTarget: Type, priority: InferencePriority = 0, eraseSignatures = false) { let symbolStack: Symbol[]; let visited: Map; let contravariant = false; - let propagationType: Type; inferFromTypes(originalSource, originalTarget); function inferFromTypes(source: Type, target: Type) { if (!couldContainTypeVariables(target)) { return; } - if (source === wildcardType) { - // We are inferring from an 'any' type. We want to infer this type for every type parameter - // referenced in the target type, so we record it as the propagation type and infer from the - // target to itself. Then, as we find candidates we substitute the propagation type. - const savePropagationType = propagationType; - propagationType = source; - inferFromTypes(target, target); - propagationType = savePropagationType; - return; - } if (source.aliasSymbol && source.aliasTypeArguments && source.aliasSymbol === target.aliasSymbol) { // Source and target are types originating in the same generic type alias declaration. // Simply infer from source type arguments to target type arguments. @@ -12597,12 +12730,11 @@ namespace ts { inference.priority = priority; } if (priority === inference.priority) { - const candidate = propagationType || source; if (contravariant) { - inference.contraCandidates = append(inference.contraCandidates, candidate); + inference.contraCandidates = append(inference.contraCandidates, source); } else { - inference.candidates = append(inference.candidates, candidate); + inference.candidates = append(inference.candidates, source); } } if (!(priority & InferencePriority.ReturnType) && target.flags & TypeFlags.TypeParameter && !isTypeParameterAtTopLevel(originalTarget, target)) { @@ -12651,11 +12783,29 @@ namespace ts { inferFromTypes(getTrueTypeFromConditionalType(source), getTrueTypeFromConditionalType(target)); inferFromTypes(getFalseTypeFromConditionalType(source), getFalseTypeFromConditionalType(target)); } - else if (target.flags & TypeFlags.UnionOrIntersection) { - const targetTypes = (target).types; + else if (target.flags & TypeFlags.Union) { + const targetTypes = (target).types; + // Make regular inference to each type in union that isn't a type variable + // or make a secondary inference to the source for every type variable. + // If a better inference comes along it will overwrite this one, and if one doesn't then + // a broad inference is better than no inference at all. + for (const t of targetTypes) { + if (getInferenceInfoForType(t)) { + const savePriority = priority; + priority |= InferencePriority.NakedTypeVariable; + inferFromTypes(source, t); + priority = savePriority; + } + else { + inferFromTypes(source, t); + } + } + } + else if (target.flags & TypeFlags.Intersection) { + const targetTypes = (target).types; let typeVariableCount = 0; let typeVariable: TypeParameter | IndexedAccessType | undefined; - // First infer to each type in union or intersection that isn't a type variable + // First infer to each type in intersection that isn't a type variable for (const t of targetTypes) { if (getInferenceInfoForType(t)) { typeVariable = t; @@ -12799,7 +12949,15 @@ namespace ts { const targetLen = targetSignatures.length; const len = sourceLen < targetLen ? sourceLen : targetLen; for (let i = 0; i < len; i++) { - inferFromSignature(getBaseSignature(sourceSignatures[sourceLen - len + i]), getBaseSignature(targetSignatures[targetLen - len + i])); + let sourceSig = sourceSignatures[sourceLen - len + i]; + const targetSig = targetSignatures[targetLen - len + i]; + if (strictFunctionTypes && !eraseSignatures && !sourceSig.isContextuallyTyped && sourceSig.typeParameters && sourceSig.typeParameters !== targetSig.typeParameters) { + sourceSig = instantiateSignatureInContextOf(sourceSig, targetSig); + inferFromSignature(sourceSig, targetSig); + } + else { + inferFromSignature(getBaseSignature(sourceSig), getBaseSignature(targetSig)); + } } } @@ -12924,7 +13082,14 @@ namespace ts { // We only have contravariant inferences, infer the best common subtype of those inferredType = getContravariantInference(inference); } - else if (context.flags & InferenceFlags.NoDefault) { + } + else { + inferredType = inference.candidates ? getUnionType(inference.candidates, UnionReduction.Subtype) : + inference.contraCandidates ? getIntersectionType(inference.contraCandidates) : undefined; + } + + if (!inferredType) { + if (context.flags & InferenceFlags.NoDefault) { // We use silentNeverType as the wildcard that signals no inferences. inferredType = silentNeverType; } @@ -12943,27 +13108,30 @@ namespace ts { createBackreferenceMapper(context.signature!.typeParameters!, index), context)); } - else { + else if (!strictFunctionTypes || context.flags & InferenceFlags.AlwaysDefault) { inferredType = getDefaultTypeArgumentType(!!(context.flags & InferenceFlags.AnyDefault)); } } } - else { - inferredType = getTypeFromInference(inference); + else if (inferredType !== inference.typeParameter && !!filter(getFreeTypeParameters(inferredType), tp => contains(context.typeParameters, tp)).length) { + inference.inferredType = neverType; + inferredType = instantiateType(inferredType, context); } - inference.inferredType = inferredType; - const constraint = getConstraintOfTypeParameter(inference.typeParameter); - if (constraint) { - const instantiatedConstraint = instantiateType(constraint, context); - if (!context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) { - inference.inferredType = inferredType = instantiatedConstraint; + if (inferredType && inferredType !== inference.typeParameter) { + const constraint = getConstraintOfTypeParameter(inference.typeParameter); + if (constraint) { + const instantiatedConstraint = instantiateType(constraint, context); + if (!context.compareTypes(inferredType, getTypeWithThisArgument(instantiatedConstraint, inferredType))) { + inference.inferredType = inferredType = instantiatedConstraint; + return instantiatedConstraint; + } } } } - return inferredType; + return inference.inferredType || inference.typeParameter; } function getDefaultTypeArgumentType(isInJavaScriptFile: boolean): Type { @@ -17843,11 +18011,12 @@ namespace ts { const context = createInferenceContext(signature.typeParameters!, signature, InferenceFlags.InferUnionTypes, compareTypes); forEachMatchingParameterType(contextualSignature, signature, (source, target) => { // Type parameters from outer context referenced by source type are fixed by instantiation of the source type - inferTypes(context.inferences, instantiateType(source, contextualMapper || identityMapper), target); + inferTypes(context.inferences, instantiateType(source, contextualMapper || identityMapper), target, /*priority*/ 0, /*eraseSignatures*/ true); }); - if (!contextualMapper) { - inferTypes(context.inferences, getReturnTypeOfSignature(contextualSignature), getReturnTypeOfSignature(signature), InferencePriority.ReturnType); - } + + const contextualReturnType = instantiateType(getReturnTypeOfSignature(contextualSignature), contextualMapper ? cloneTypeMapper(contextualMapper) : identityMapper); + inferTypes(context.inferences, contextualReturnType, getReturnTypeOfSignature(signature), InferencePriority.ReturnType, /*eraseSignatures*/ true); + return getSignatureInstantiation(signature, getInferredTypes(context), isInJavaScriptFile(contextualSignature.declaration)); } @@ -18045,7 +18214,14 @@ namespace ts { // If the effective argument is 'undefined', then it is an argument that is present but is synthetic. if (arg === undefined || arg.kind !== SyntaxKind.OmittedExpression) { // Check spread elements against rest type (from arity check we know spread argument corresponds to a rest parameter) - const paramType = getTypeAtPosition(signature, i); + let paramType = getTypeAtPosition(signature, i); + if (excludeArgument && excludeArgument[i] && signature.inferenceContext) { + // there could be an uninferred type parameter here (that will be inferred on the next pass when this argument isn't excluded.) + // so this code makes the inference context replace any uninferred types with noInferenceType so the assignment check below doesn't fail. + signature.inferenceContext.useEmptyObjectForNoInference = true; + paramType = instantiateType(paramType, signature.inferenceContext); + signature.inferenceContext.useEmptyObjectForNoInference = false; + } // If the effective argument type is undefined, there is no synthetic type for the argument. // In that case, we should check the argument. const argType = getEffectiveArgumentType(node, i) || @@ -18053,7 +18229,10 @@ namespace ts { // If one or more arguments are still excluded (as indicated by a non-null excludeArgument parameter), // we obtain the regular type of any object literal arguments because we may not have inferred complete // parameter types yet and therefore excess property checks may yield false positives (see #17041). - const checkArgType = excludeArgument ? getRegularTypeOfObjectLiteral(argType) : argType; + let checkArgType = excludeArgument ? getRegularTypeOfObjectLiteral(argType) : argType; + if (arg && arg.contextualTypeParameters && signature.mapper) { + checkArgType = instantiateType(checkArgType, createTypeMapper(arg.contextualTypeParameters, map(arg.contextualTypeParameters, signature.mapper))); + } // Use argument expression as error location when reporting errors const errorNode = reportErrors ? getEffectiveArgumentErrorNode(node, i, arg) : undefined; if (!checkTypeRelatedTo(checkArgType, paramType, relation, errorNode, headMessage)) { @@ -18454,6 +18633,8 @@ namespace ts { } } } + const originalExcludeArgument = excludeArgument ? excludeArgument.slice() : undefined; + const originalExcludeCount = excludeCount; // The following variables are captured and modified by calls to chooseOverload. // If overload resolution or type argument inference fails, we want to report the @@ -18502,6 +18683,23 @@ namespace ts { result = chooseOverload(candidates, assignableRelation, signatureHelpTrailingComma); } if (result) { + if (result.inferenceContext) { + const argTypes = map(filter(args, a => !!a), a => getTypeOfExpression(a, /*cache*/ false)); + const argTypeParameters = flatMap(argTypes, getFreeTypeParameters); + const contextualType = isDecorator ? undefined : getContextualType(node); + const contextualTypeParameters = contextualType ? getFreeTypeParameters(contextualType) : emptyArray; + const outerTypeParameters = getOuterTypeParameters(node); + const candidateTypeParametersNotAlsoOuter = filter(result.target!.typeParameters!, tp => !contains(outerTypeParameters, tp)); + const possibleTypeParameters = concatenate(argTypeParameters, concatenate(outerTypeParameters, contextualTypeParameters)); + const typeParametersToIgnore = filter(possibleTypeParameters, tp => !contains(candidateTypeParametersNotAlsoOuter, tp)); + const resultReturnType = getReturnTypeOfSignature(result); + const newReturnType = handleFreeTypeParameters(resultReturnType, typeParametersToIgnore, isInJavaScriptFile(node)); + if (newReturnType !== resultReturnType) { + const newResult = cloneSignature(result); + newResult.resolvedReturnType = newReturnType; + return newResult; + } + } return result; } @@ -18607,6 +18805,9 @@ namespace ts { if (!hasCorrectArity(node, args!, originalCandidate, signatureHelpTrailingComma)) { continue; } + if (candidateIndex > 0) { + resetContextualArguments(); + } let candidate: Signature; const inferenceContext = originalCandidate.typeParameters ? @@ -18632,6 +18833,9 @@ namespace ts { } const isJavascript = isInJavaScriptFile(candidate.declaration); candidate = getSignatureInstantiation(candidate, typeArgumentTypes, isJavascript); + if (!typeArguments) { + candidate.inferenceContext = inferenceContext; + } } if (!checkApplicableSignature(node, args!, candidate, relation, excludeArgument, /*reportErrors*/ false)) { candidateForArgumentError = candidate; @@ -18653,6 +18857,47 @@ namespace ts { return undefined; } + + function resetContextualArguments() { + if (!isDecorator && !isSingleNonGenericCandidate && originalExcludeArgument) { + excludeArgument = originalExcludeArgument.slice(); + excludeCount = originalExcludeCount; + for (let i = isTaggedTemplate ? 1 : 0; i < args!.length; i++) { + visitContextSensitive(args![i], visit); + } + } + + function visit(contextSensitiveFunction: FunctionExpression | ArrowFunction | MethodDeclaration) { + const nodeLinks = getNodeLinks(contextSensitiveFunction); + + if (nodeLinks.flags & NodeCheckFlags.ContextChecked) { + const functionSymbol = getMergedSymbol(contextSensitiveFunction.symbol); + const symbolLinks = getSymbolLinks(functionSymbol); + const oldType = symbolLinks.type; + Debug.assertDefined(oldType); + const oldSignature = getSignaturesOfType(oldType!, SignatureKind.Call)[0]; + for (const p of oldSignature.parameters) { + if (isTransientSymbol(p) || !getEffectiveTypeAnnotationNode(p.valueDeclaration)) { + getSymbolLinks(p).outerTypeParameters = undefined; + getSymbolLinks(p).type = undefined; + } + } + if (!getEffectiveReturnTypeNode(contextSensitiveFunction)) { + const oldReturnType = oldSignature.resolvedReturnType; + if (oldReturnType && oldReturnType.symbol) { + getSymbolLinks(oldReturnType.symbol).outerTypeParameters = undefined; + } + oldSignature.resolvedReturnType = undefined; + } + symbolLinks.type = undefined; + symbolLinks.outerTypeParameters = undefined; + contextSensitiveFunction.contextualTypeParameters = undefined; + nodeLinks.flags &= ~NodeCheckFlags.ContextChecked; + nodeLinks.flags |= NodeCheckFlags.ContextReset; + } + } + + } } function getLongestCandidateIndex(candidates: Signature[], argsCount: number): number { @@ -19420,7 +19665,7 @@ namespace ts { } } - function assignContextualParameterTypes(signature: Signature, context: Signature) { + function assignContextualParameterTypes(signature: Signature, context: Signature, node: Node) { signature.typeParameters = context.typeParameters; if (context.thisParameter) { const parameter = signature.thisParameter; @@ -19436,7 +19681,11 @@ namespace ts { const parameter = signature.parameters[i]; if (!getEffectiveTypeAnnotationNode(parameter.valueDeclaration)) { const contextualParameterType = getTypeAtPosition(context, i); - assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType); + const originalContextualParameterType = signature.isContextuallyTyped ? getTypeAtPosition(context.target!, i) : undefined; + assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, contextualParameterType === originalContextualParameterType); + for (const tp of getFreeTypeParameters(contextualParameterType)) { + node.contextualTypeParameters = appendIfUnique(node.contextualTypeParameters, tp); + } } } if (signature.hasRestParameter && isRestParameterIndex(context, signature.parameters.length - 1)) { @@ -19444,7 +19693,11 @@ namespace ts { const parameter = last(signature.parameters); if (isTransientSymbol(parameter) || !getEffectiveTypeAnnotationNode(parameter.valueDeclaration)) { const contextualParameterType = getTypeOfSymbol(last(context.parameters)); - assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType); + const originalContextualParameterType = signature.isContextuallyTyped ? getTypeOfSymbol(last(context.target!.parameters)) : undefined; + assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, contextualParameterType === originalContextualParameterType); + for (const tp of getFreeTypeParameters(contextualParameterType)) { + node.contextualTypeParameters = appendIfUnique(node.contextualTypeParameters, tp); + } } } } @@ -19464,14 +19717,14 @@ namespace ts { } } - function assignTypeToParameterAndFixTypeParameters(parameter: Symbol, contextualType: Type) { + function assignTypeToParameterAndFixTypeParameters(parameter: Symbol, contextualType: Type, noInference?: boolean) { const links = getSymbolLinks(parameter); if (!links.type) { links.type = contextualType; const decl = parameter.valueDeclaration as ParameterDeclaration; if (decl.name.kind !== SyntaxKind.Identifier) { // if inference didn't come up with anything but {}, fall back to the binding pattern if present. - if (links.type === emptyObjectType) { + if (links.type === emptyObjectType || (links.type.flags & TypeFlags.TypeParameter && noInference)) { links.type = getTypeFromBindingPattern(decl.name); } assignBindingElementTypes(decl.name); @@ -19786,7 +20039,13 @@ namespace ts { } const instantiatedContextualSignature = contextualMapper === identityMapper ? contextualSignature : instantiateSignature(contextualSignature, contextualMapper); - assignContextualParameterTypes(signature, instantiatedContextualSignature); + if (isInferenceContext(contextualMapper)) { + signature.isContextuallyTyped = true; + assignContextualParameterTypes(signature, instantiatedContextualSignature, node); + } + else { + assignContextualParameterTypes(signature, instantiatedContextualSignature, node); + } } if (!getEffectiveReturnTypeNode(node) && !signature.resolvedReturnType) { const returnType = getReturnTypeFromBody(node, checkMode); @@ -19796,7 +20055,9 @@ namespace ts { } } checkSignatureDeclaration(node); - checkNodeDeferred(node); + if (!(links.flags & NodeCheckFlags.ContextReset)) { + checkNodeDeferred(node); + } } } diff --git a/src/compiler/types.ts b/src/compiler/types.ts index 3a19762f0a996..fa6e9550a9f8f 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -589,6 +589,7 @@ namespace ts { /* @internal */ emitNode?: EmitNode; // Associated EmitNode (initialized by transforms) /* @internal */ contextualType?: Type; // Used to temporarily assign a contextual type during overload resolution /* @internal */ contextualMapper?: TypeMapper; // Mapper for contextual type + /* @internal */ contextualTypeParameters?: TypeParameter[]; // Type parameters from contextual type. Not temporary like contextualType and contextualMapper. } export interface JSDocContainer { @@ -1096,6 +1097,9 @@ namespace ts { kind: SyntaxKind.ThisType; } + /* @internal */ + export type MaybeContextSensitive = Expression | MethodDeclaration | ObjectLiteralElementLike | JsxAttributeLike; + export type FunctionOrConstructorTypeNode = FunctionTypeNode | ConstructorTypeNode; export interface FunctionTypeNode extends TypeNode, SignatureDeclarationBase { @@ -3643,6 +3647,7 @@ namespace ts { AssignmentsMarked = 0x00400000, // Parameter assignments have been marked ClassWithConstructorReference = 0x00800000, // Class that contains a binding to its constructor inside of the class body. ConstructorReferenceInClass = 0x01000000, // Binding to a class constructor inside of the class's body. + ContextReset = 0x02000000, // Contextual types were previously set but have been cleared. This means the node does not need to be added to deferredNodes again. } /* @internal */ @@ -3772,6 +3777,8 @@ namespace ts { aliasTypeArguments?: Type[]; // Alias type arguments (if any) /* @internal */ wildcardInstantiation?: Type; // Instantiation with type parameters mapped to wildcard type + /* @internal */ + freeTypeParameters?: TypeParameter[]; } /* @internal */ @@ -3913,6 +3920,7 @@ namespace ts { export interface AnonymousType extends ObjectType { target?: AnonymousType; // Instantiation target mapper?: TypeMapper; // Instantiation mapper + typeArguments?: Type[]; } /* @internal */ @@ -4098,6 +4106,10 @@ namespace ts { isolatedSignatureType?: ObjectType; // A manufactured type that just contains the signature for purposes of signature comparison /* @internal */ instantiations?: Map; // Generic signature instantiation cache + /* @internal */ + inferenceContext?: InferenceContext; + /* @internal */ + isContextuallyTyped?: boolean; } export const enum IndexKind { @@ -4143,6 +4155,7 @@ namespace ts { InferUnionTypes = 1 << 0, // Infer union types for disjoint candidates (otherwise unknownType) NoDefault = 1 << 1, // Infer unknownType for no inferences (otherwise anyType or emptyObjectType) AnyDefault = 1 << 2, // Infer anyType for no inferences (otherwise emptyObjectType) + AlwaysDefault = 1 << 3, // Infer the default type if there are no candidates or constraints (otherwise no inference is made and type parameter is returned) } /** @@ -4171,6 +4184,7 @@ namespace ts { inferences: InferenceInfo[]; // Inferences made for each type parameter flags: InferenceFlags; // Inference flags compareTypes: TypeComparer; // Type comparer function + useEmptyObjectForNoInference?: boolean; } /* @internal */ From 2e51a07a66e9ae3d5c9c6eb5cb8e2cfa0d02258e Mon Sep 17 00:00:00 2001 From: Kevin Donnelly Date: Sat, 2 Jun 2018 11:54:42 -0500 Subject: [PATCH 3/4] Update baselines. --- .../baselines/reference/conditionalTypes1.js | 5 +- .../reference/conditionalTypes1.types | 4 +- .../contextualTypingOfTooShortOverloads.types | 14 +- .../reference/genericContextualTypes1.types | 10 +- ...TypeParameterEquivalence2strict.errors.txt | 89 ----- ...nericTypeParameterEquivalence2strict.types | 36 +-- tests/baselines/reference/inferTypes1.types | 2 +- ...inferentialTypingWithFunctionTypeZip.types | 8 +- ...icFunctionsFromGenericFunctions.errors.txt | 68 ---- ...GenericFunctionsFromGenericFunctions.types | 28 +- ...cFunctionsFromGenericFunctions2.errors.txt | 111 +------ ...enericFunctionsFromGenericFunctions2.types | 106 +++--- ...nsFromGenericFunctionsContexual.errors.txt | 192 ----------- ...nctionsFromGenericFunctionsContexual.types | 304 +++++++++--------- .../intersectionsOfLargeUnions.types | 4 +- .../reference/jqueryInference.errors.txt | 20 ++ .../baselines/reference/jqueryInference.types | 6 +- ...nWithConstraintCheckingDeferred.errors.txt | 11 +- ...lutionWithConstraintCheckingDeferred.types | 22 +- .../parenthesizedContexualTyping1.types | 24 +- 20 files changed, 316 insertions(+), 748 deletions(-) delete mode 100644 tests/baselines/reference/genericTypeParameterEquivalence2strict.errors.txt delete mode 100644 tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.errors.txt delete mode 100644 tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.errors.txt create mode 100644 tests/baselines/reference/jqueryInference.errors.txt diff --git a/tests/baselines/reference/conditionalTypes1.js b/tests/baselines/reference/conditionalTypes1.js index 552a80d58a53b..363fd49f024bb 100644 --- a/tests/baselines/reference/conditionalTypes1.js +++ b/tests/baselines/reference/conditionalTypes1.js @@ -499,10 +499,9 @@ declare type T15 = Extract(p: K): Extract; -declare let x0: { +declare let x0: Extract; declare type OptionsOfKind = Extract; diff --git a/tests/baselines/reference/conditionalTypes1.types b/tests/baselines/reference/conditionalTypes1.types index 5b0cb6dd8383a..498bca70f9606 100644 --- a/tests/baselines/reference/conditionalTypes1.types +++ b/tests/baselines/reference/conditionalTypes1.types @@ -187,8 +187,8 @@ declare function f5(p: K): ExtractK : K let x0 = f5("a"); // { k: "a", a: number } ->x0 : { k: "a"; a: number; } ->f5("a") : { k: "a"; a: number; } +>x0 : Extract +>f5("a") : Extract >f5 : (p: K) => Extract >"a" : "a" diff --git a/tests/baselines/reference/contextualTypingOfTooShortOverloads.types b/tests/baselines/reference/contextualTypingOfTooShortOverloads.types index 769bd55d4b57b..ada80fe24ac79 100644 --- a/tests/baselines/reference/contextualTypingOfTooShortOverloads.types +++ b/tests/baselines/reference/contextualTypingOfTooShortOverloads.types @@ -7,9 +7,9 @@ var use: Overload; use((req, res) => {}); >use((req, res) => {}) : void >use : Overload ->(req, res) => {} : (req: any, res: any) => void ->req : any ->res : any +>(req, res) => {} : (req: number, res: number) => void +>req : number +>res : number interface Overload { >Overload : Overload @@ -33,11 +33,11 @@ app.use((err: any, req, res, next) => { return; }); >app.use : IRouterHandler & IRouterMatcher >app : MyApp >use : IRouterHandler & IRouterMatcher ->(err: any, req, res, next) => { return; } : (err: any, req: any, res: any, next: any) => void +>(err: any, req, res, next) => { return; } : (err: any, req: Request, res: Response, next: NextFunction) => void >err : any ->req : any ->res : any ->next : any +>req : Request +>res : Response +>next : NextFunction interface MyApp { diff --git a/tests/baselines/reference/genericContextualTypes1.types b/tests/baselines/reference/genericContextualTypes1.types index b1a7aff8eef9f..e8584cab30748 100644 --- a/tests/baselines/reference/genericContextualTypes1.types +++ b/tests/baselines/reference/genericContextualTypes1.types @@ -136,7 +136,7 @@ const f02: (x: A) => A[] = wrap(list); >x : A >A : A >A : A ->wrap(list) : (a: A) => A[] +>wrap(list) : (a: A) => A[] >wrap : (f: (a: A) => B) => (a: A) => B >list : (a: T) => T[] @@ -180,7 +180,7 @@ const f11: (x: T) => Box = compose(list, box); >T : T >Box : Box >T : T ->compose(list, box) : (a: T) => Box +>compose(list, box) : (a: T) => Box >compose : (f: (a: A) => B, g: (b: B) => C) => (a: A) => C >list : (a: T) => T[] >box : (x: V) => Box @@ -212,7 +212,7 @@ const f13: (x: Box) => T = compose(unbox, unlist); >Box : Box >T : T >T : T ->compose(unbox, unlist) : (a: Box) => T +>compose(unbox, unlist) : (a: Box) => T >compose : (f: (a: A) => B, g: (b: B) => C) => (a: A) => C >unbox : (x: Box) => W >unlist : (a: T[]) => T @@ -281,7 +281,7 @@ const f22: (a: A[]) => A[] = arrayMap(identity); >a : A[] >A : A >A : A ->arrayMap(identity) : (a: A[]) => A[] +>arrayMap(identity) : (a: A[]) => A[] >arrayMap : (f: (x: T) => U) => (a: T[]) => U[] >identity : (x: T) => T @@ -340,7 +340,7 @@ const f40: (b: B, a: A) => [A, B] = flip(zip); >A : A >A : A >B : B ->flip(zip) : (y: B, x: A) => [A, B] +>flip(zip) : (y: B, x: A) => [A, B] >flip : (f: (x: X, y: Y) => Z) => (y: Y, x: X) => Z >zip : (a: A, b: B) => [A, B] diff --git a/tests/baselines/reference/genericTypeParameterEquivalence2strict.errors.txt b/tests/baselines/reference/genericTypeParameterEquivalence2strict.errors.txt deleted file mode 100644 index d2e24776fabe6..0000000000000 --- a/tests/baselines/reference/genericTypeParameterEquivalence2strict.errors.txt +++ /dev/null @@ -1,89 +0,0 @@ -tests/cases/compiler/genericTypeParameterEquivalence2strict.ts(41,22): error TS2345: Argument of type '(f: (a: A) => boolean, ar: A[]) => A[]' is not assignable to parameter of type '(a: {}, b: {}) => {}[]'. - Types of parameters 'f' and 'a' are incompatible. - Type '{}' is not assignable to type '(a: {}) => boolean'. - Type '{}' provides no match for the signature '(a: {}): boolean'. -tests/cases/compiler/genericTypeParameterEquivalence2strict.ts(59,20): error TS2345: Argument of type '(ar: A[]) => number' is not assignable to parameter of type '(b: {}) => number'. - Types of parameters 'ar' and 'b' are incompatible. - Type '{}' is not assignable to type '{}[]'. - Property 'length' is missing in type '{}'. -tests/cases/compiler/genericTypeParameterEquivalence2strict.ts(64,20): error TS2345: Argument of type '(ar: A[]) => number' is not assignable to parameter of type '(b: {}) => number'. - - -==== tests/cases/compiler/genericTypeParameterEquivalence2strict.ts (3 errors) ==== - // compose :: (b->c) -> (a->b) -> (a->c) - function compose(f: (b: B) => C, g: (a:A) => B): (a:A) => C { - return function (a:A) : C { - return f(g.apply(null, a)); - }; - } - - // forEach :: [a] -> (a -> ()) -> () - function forEach(list: A[], f: (a: A, n?: number) => void ): void { - for (var i = 0; i < list.length; ++i) { - f(list[i], i); - } - } - - // filter :: (a->bool) -> [a] -> [a] - function filter(f: (a: A) => boolean, ar: A[]): A[] { - var ret: A[] = []; - forEach(ar, (el) => { - if (f(el)) { - ret.push(el); - } - } ); - - return ret; - } - - // length :: [a] -> Num - function length2(ar: A[]): number { - return ar.length; - } - - // curry1 :: ((a,b)->c) -> (a->(b->c)) - function curry1(f: (a: A, b: B) => C): (ax: A) => (bx: B) => C { - return function (ay: A) { - return function (by: B) { - return f(ay, by); - }; - }; - } - - var cfilter = curry1(filter); - ~~~~~~ -!!! error TS2345: Argument of type '(f: (a: A) => boolean, ar: A[]) => A[]' is not assignable to parameter of type '(a: {}, b: {}) => {}[]'. -!!! error TS2345: Types of parameters 'f' and 'a' are incompatible. -!!! error TS2345: Type '{}' is not assignable to type '(a: {}) => boolean'. -!!! error TS2345: Type '{}' provides no match for the signature '(a: {}): boolean'. - - declare function strBool(str: string): boolean - const filterer = cfilter(strBool); - const expectFilterer: (a: string[]) => string[] = filterer; - - const filtered = filterer(["hello"]); - const expectFiltered: string[] = filtered; - - // compose :: (b->c) -> (a->b) -> (a->c) - // length :: [a] -> Num - // cfilter :: {} -> {} -> [{}] - // pred :: a -> Bool - // cfilter(pred) :: {} -> [{}] - // length2 :: [a] -> Num - // countWhere :: (a -> Bool) -> [a] -> Num - - function countWhere_1(pred: (a: A) => boolean): (a: A[]) => number { - return compose(length2, cfilter(pred)); - ~~~~~~~ -!!! error TS2345: Argument of type '(ar: A[]) => number' is not assignable to parameter of type '(b: {}) => number'. -!!! error TS2345: Types of parameters 'ar' and 'b' are incompatible. -!!! error TS2345: Type '{}' is not assignable to type '{}[]'. -!!! error TS2345: Property 'length' is missing in type '{}'. - } - - function countWhere_2(pred: (a: A) => boolean): (a: A[]) => number { - var where = cfilter(pred); - return compose(length2, where); - ~~~~~~~ -!!! error TS2345: Argument of type '(ar: A[]) => number' is not assignable to parameter of type '(b: {}) => number'. - } \ No newline at end of file diff --git a/tests/baselines/reference/genericTypeParameterEquivalence2strict.types b/tests/baselines/reference/genericTypeParameterEquivalence2strict.types index 6109caa3227c3..a93b3dd47c616 100644 --- a/tests/baselines/reference/genericTypeParameterEquivalence2strict.types +++ b/tests/baselines/reference/genericTypeParameterEquivalence2strict.types @@ -161,8 +161,8 @@ function curry1(f: (a: A, b: B) => C): (ax: A) => (bx: B) => C { } var cfilter = curry1(filter); ->cfilter : any ->curry1(filter) : any +>cfilter : (ax: (a: A) => boolean) => (bx: A[]) => A[] +>curry1(filter) : (ax: (a: A) => boolean) => (bx: A[]) => A[] >curry1 : (f: (a: A, b: B) => C) => (ax: A) => (bx: B) => C >filter : (f: (a: A) => boolean, ar: A[]) => A[] @@ -171,26 +171,26 @@ declare function strBool(str: string): boolean >str : string const filterer = cfilter(strBool); ->filterer : any ->cfilter(strBool) : any ->cfilter : any +>filterer : (bx: string[]) => string[] +>cfilter(strBool) : (bx: string[]) => string[] +>cfilter : (ax: (a: A) => boolean) => (bx: A[]) => A[] >strBool : (str: string) => boolean const expectFilterer: (a: string[]) => string[] = filterer; >expectFilterer : (a: string[]) => string[] >a : string[] ->filterer : any +>filterer : (bx: string[]) => string[] const filtered = filterer(["hello"]); ->filtered : any ->filterer(["hello"]) : any ->filterer : any +>filtered : string[] +>filterer(["hello"]) : string[] +>filterer : (bx: string[]) => string[] >["hello"] : string[] >"hello" : "hello" const expectFiltered: string[] = filtered; >expectFiltered : string[] ->filtered : any +>filtered : string[] // compose :: (b->c) -> (a->b) -> (a->c) // length :: [a] -> Num @@ -210,11 +210,11 @@ function countWhere_1(pred: (a: A) => boolean): (a: A[]) => number { >A : A return compose(length2, cfilter(pred)); ->compose(length2, cfilter(pred)) : any +>compose(length2, cfilter(pred)) : (a: A[]) => number >compose : (f: (b: B) => C, g: (a: A) => B) => (a: A) => C >length2 : (ar: A[]) => number ->cfilter(pred) : any ->cfilter : any +>cfilter(pred) : (bx: A[]) => A[] +>cfilter : (ax: (a: A) => boolean) => (bx: A[]) => A[] >pred : (a: A) => boolean } @@ -228,14 +228,14 @@ function countWhere_2(pred: (a: A) => boolean): (a: A[]) => number { >A : A var where = cfilter(pred); ->where : any ->cfilter(pred) : any ->cfilter : any +>where : (bx: A[]) => A[] +>cfilter(pred) : (bx: A[]) => A[] +>cfilter : (ax: (a: A) => boolean) => (bx: A[]) => A[] >pred : (a: A) => boolean return compose(length2, where); ->compose(length2, where) : any +>compose(length2, where) : (a: A[]) => number >compose : (f: (b: B) => C, g: (a: A) => B) => (a: A) => C >length2 : (ar: A[]) => number ->where : any +>where : (bx: A[]) => A[] } diff --git a/tests/baselines/reference/inferTypes1.types b/tests/baselines/reference/inferTypes1.types index 3138341592d0d..c513ce6da9882 100644 --- a/tests/baselines/reference/inferTypes1.types +++ b/tests/baselines/reference/inferTypes1.types @@ -94,7 +94,7 @@ type T12 = ReturnType<(() => T)>; // {} >T : T type T13 = ReturnType<(() => T)>; // number[] ->T13 : number[] +>T13 : ReturnType<(() => T)> >ReturnType : ReturnType >T : T >U : U diff --git a/tests/baselines/reference/inferentialTypingWithFunctionTypeZip.types b/tests/baselines/reference/inferentialTypingWithFunctionTypeZip.types index 58d51e48987f4..8c1e019c7ae93 100644 --- a/tests/baselines/reference/inferentialTypingWithFunctionTypeZip.types +++ b/tests/baselines/reference/inferentialTypingWithFunctionTypeZip.types @@ -30,8 +30,8 @@ var zipWith: (a: T[], b: S[], f: (x: T) => (y: S) => U) => U[]; >U : U var result = zipWith([1, 2], ['a', 'b'], pair); ->result : { x: number; y: {}; }[] ->zipWith([1, 2], ['a', 'b'], pair) : { x: number; y: {}; }[] +>result : { x: number; y: string; }[] +>zipWith([1, 2], ['a', 'b'], pair) : { x: number; y: string; }[] >zipWith : (a: T[], b: S[], f: (x: T) => (y: S) => U) => U[] >[1, 2] : number[] >1 : 1 @@ -44,8 +44,8 @@ var result = zipWith([1, 2], ['a', 'b'], pair); var i = result[0].x; // number >i : number >result[0].x : number ->result[0] : { x: number; y: {}; } ->result : { x: number; y: {}; }[] +>result[0] : { x: number; y: string; } +>result : { x: number; y: string; }[] >0 : 0 >x : number diff --git a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.errors.txt b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.errors.txt deleted file mode 100644 index e8eda2caa3955..0000000000000 --- a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.errors.txt +++ /dev/null @@ -1,68 +0,0 @@ -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions.ts(14,5): error TS2322: Type '(b: {}, a: {}) => [{}, {}]' is not assignable to type '(y: U, x: T) => [T, U]'. - Type '[{}, {}]' is not assignable to type '[T, U]'. - Type '{}' is not assignable to type 'T'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions.ts(17,7): error TS2322: Type '[{}, {}]' is not assignable to type '[number, string]'. - Type '{}' is not assignable to type 'number'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions.ts(29,7): error TS2322: Type '(x: {}) => { value: {}[]; }' is not assignable to type '(u: U) => { value: U[]; }'. - Type '{ value: {}[]; }' is not assignable to type '{ value: U[]; }'. - Types of property 'value' are incompatible. - Type '{}[]' is not assignable to type 'U[]'. - Type '{}' is not assignable to type 'U'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions.ts(33,7): error TS2322: Type '{ value: {}[]; }' is not assignable to type '{ value: string[]; }'. - Types of property 'value' are incompatible. - Type '{}[]' is not assignable to type 'string[]'. - Type '{}' is not assignable to type 'string'. - - -==== tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions.ts (4 errors) ==== - export {} - - - // example from https://github.com/Microsoft/TypeScript/issues/9366 - - function flip(f: (a: a, b: b) => c): (b: b, a: a) => c { - return (b: b, a: a) => f(a, b); - } - function zip(x: T, y: U): [T, U] { - return [x, y]; - } - - const flipped = flip(zip); - var expected: (y: U, x: T) => [T, U] = flipped; - ~~~~~~~~ -!!! error TS2322: Type '(b: {}, a: {}) => [{}, {}]' is not assignable to type '(y: U, x: T) => [T, U]'. -!!! error TS2322: Type '[{}, {}]' is not assignable to type '[T, U]'. -!!! error TS2322: Type '{}' is not assignable to type 'T'. - - const actualCallResult = flipped("test", 1234) - const expectedResult: [number, string] = actualCallResult; - ~~~~~~~~~~~~~~ -!!! error TS2322: Type '[{}, {}]' is not assignable to type '[number, string]'. -!!! error TS2322: Type '{}' is not assignable to type 'number'. - - - - - // from https://github.com/Microsoft/TypeScript/issues/16414 - - declare function compose(f: (x: A) => B, g: (y: B) => C): (x: A) => C; - declare function box(x: T): { value: T }; - declare function list(x: U): U[]; - - const composed = compose(list, box); - const expectedComposed: (u: U) => { value: U[] } = composed; - ~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '(x: {}) => { value: {}[]; }' is not assignable to type '(u: U) => { value: U[]; }'. -!!! error TS2322: Type '{ value: {}[]; }' is not assignable to type '{ value: U[]; }'. -!!! error TS2322: Types of property 'value' are incompatible. -!!! error TS2322: Type '{}[]' is not assignable to type 'U[]'. -!!! error TS2322: Type '{}' is not assignable to type 'U'. - - - const callComposed = composed("test"); - const expectedCallComposed: { value: string[] } = callComposed; - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '{ value: {}[]; }' is not assignable to type '{ value: string[]; }'. -!!! error TS2322: Types of property 'value' are incompatible. -!!! error TS2322: Type '{}[]' is not assignable to type 'string[]'. -!!! error TS2322: Type '{}' is not assignable to type 'string'. \ No newline at end of file diff --git a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.types b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.types index e40bc0caec38b..867569dc6c9d1 100644 --- a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.types +++ b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions.types @@ -50,8 +50,8 @@ function zip(x: T, y: U): [T, U] { } const flipped = flip(zip); ->flipped : (b: {}, a: {}) => [{}, {}] ->flip(zip) : (b: {}, a: {}) => [{}, {}] +>flipped : (b: b, a: a) => [a, b] +>flip(zip) : (b: b, a: a) => [a, b] >flip : (f: (a: a, b: b) => c) => (b: b, a: a) => c >zip : (x: T, y: U) => [T, U] @@ -65,18 +65,18 @@ var expected: (y: U, x: T) => [T, U] = flipped; >T : T >T : T >U : U ->flipped : (b: {}, a: {}) => [{}, {}] +>flipped : (b: b, a: a) => [a, b] const actualCallResult = flipped("test", 1234) ->actualCallResult : [{}, {}] ->flipped("test", 1234) : [{}, {}] ->flipped : (b: {}, a: {}) => [{}, {}] +>actualCallResult : [number, string] +>flipped("test", 1234) : [number, string] +>flipped : (b: b, a: a) => [a, b] >"test" : "test" >1234 : 1234 const expectedResult: [number, string] = actualCallResult; >expectedResult : [number, string] ->actualCallResult : [{}, {}] +>actualCallResult : [number, string] @@ -116,8 +116,8 @@ declare function list(x: U): U[]; >U : U const composed = compose(list, box); ->composed : (x: {}) => { value: {}[]; } ->compose(list, box) : (x: {}) => { value: {}[]; } +>composed : (x: A) => { value: A[]; } +>compose(list, box) : (x: A) => { value: A[]; } >compose : (f: (x: A) => B, g: (y: B) => C) => (x: A) => C >list : (x: U) => U[] >box : (x: T) => { value: T; } @@ -129,17 +129,17 @@ const expectedComposed: (u: U) => { value: U[] } = composed; >U : U >value : U[] >U : U ->composed : (x: {}) => { value: {}[]; } +>composed : (x: A) => { value: A[]; } const callComposed = composed("test"); ->callComposed : { value: {}[]; } ->composed("test") : { value: {}[]; } ->composed : (x: {}) => { value: {}[]; } +>callComposed : { value: string[]; } +>composed("test") : { value: string[]; } +>composed : (x: A) => { value: A[]; } >"test" : "test" const expectedCallComposed: { value: string[] } = callComposed; >expectedCallComposed : { value: string[]; } >value : string[] ->callComposed : { value: {}[]; } +>callComposed : { value: string[]; } diff --git a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.errors.txt b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.errors.txt index 5122bdc849b18..84be0bac0f069 100644 --- a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.errors.txt +++ b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.errors.txt @@ -2,11 +2,6 @@ tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(21,32): e Type 'string' is not assignable to type 'Date'. tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(22,32): error TS2345: Argument of type '(x: number) => string' is not assignable to parameter of type '(x: number) => Date'. Type 'string' is not assignable to type 'Date'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(29,7): error TS2345: Argument of type '(x: A, l: List, y: A) => A' is not assignable to parameter of type '(l: List<{}>, x: {}, y: {}) => {}'. - Types of parameters 'l' and 'x' are incompatible. - Type '{}' is not assignable to type 'List<{}>'. - Type '{}' is not assignable to type '{ kind: "cons"; val: {}; rest: List<{}>; }'. - Property 'kind' is missing in type '{}'. tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(37,11): error TS2345: Argument of type '(x: T, y: U) => U' is not assignable to parameter of type '(x: string, y: number) => string'. Types of parameters 'y' and 'y' are incompatible. Type 'number' is not assignable to type 'string'. @@ -16,7 +11,7 @@ tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(38,12): e tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(39,26): error TS2345: Argument of type '(x: T, y: U) => U' is not assignable to parameter of type '(x: string, y: number) => string | number'. Types of parameters 'y' and 'y' are incompatible. Type 'number' is not assignable to type 'string'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(41,12): error TS2345: Argument of type '(x: T, y: U, z: V) => V' is not assignable to parameter of type '(x: string, y: number, z: {}) => {}'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(41,12): error TS2345: Argument of type '(x: T, y: U, z: V) => V' is not assignable to parameter of type '(x: string, y: number, z: string) => string'. Types of parameters 'y' and 'y' are incompatible. Type 'number' is not assignable to type 'string'. tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(42,27): error TS2345: Argument of type '(x: T, y: U, z: V) => V' is not assignable to parameter of type '(x: string, y: number, z: string | number) => string | number'. @@ -39,26 +34,6 @@ tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(99,13): e Property 'y' is missing in type 'A'. tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(104,5): error TS2345: Argument of type '(x: number) => number' is not assignable to parameter of type '(x: number) => 4'. Type 'number' is not assignable to type '4'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(109,7): error TS2345: Argument of type '({ a }: { a: any; }) => any' is not assignable to parameter of type '(x: {}) => string'. - Types of parameters '__0' and 'x' are incompatible. - Type '{}' is not assignable to type '{ a: any; }'. - Property 'a' is missing in type '{}'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(110,7): error TS2345: Argument of type '([b, c]: [any, any]) => string' is not assignable to parameter of type '(x: {}) => string'. - Types of parameters '__0' and 'x' are incompatible. - Type '{}' is not assignable to type '[any, any]'. - Property '0' is missing in type '{}'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(111,7): error TS2345: Argument of type '({ d: [e, f] }: { d: [any, any]; }) => string' is not assignable to parameter of type '(x: {}) => string'. - Types of parameters '__0' and 'x' are incompatible. - Type '{}' is not assignable to type '{ d: [any, any]; }'. - Property 'd' is missing in type '{}'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(112,7): error TS2345: Argument of type '([{ g }, { h }]: [{ g: any; }, { h: any; }]) => string' is not assignable to parameter of type '(x: {}) => string'. - Types of parameters '__0' and 'x' are incompatible. - Type '{}' is not assignable to type '[{ g: any; }, { h: any; }]'. - Property '0' is missing in type '{}'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(113,7): error TS2345: Argument of type '({ a, b }: { a: any; b?: number; }) => any' is not assignable to parameter of type '(x: {}) => string'. - Types of parameters '__0' and 'x' are incompatible. - Type '{}' is not assignable to type '{ a: any; b?: number; }'. - Property 'a' is missing in type '{}'. tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(120,24): error TS2345: Argument of type '(x: T, y: U) => U' is not assignable to parameter of type '(x: number, y: string) => number'. Types of parameters 'y' and 'y' are incompatible. Type 'string' is not assignable to type 'number'. @@ -68,13 +43,6 @@ tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(132,12): tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(133,11): error TS2345: Argument of type '(x: N) => N' is not assignable to parameter of type '(x: string) => string'. Types of parameters 'x' and 'x' are incompatible. Type 'string' is not assignable to type 'number'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(141,7): error TS2322: Type '[{}, {}]' is not assignable to type '[number, string]'. - Type '{}' is not assignable to type 'number'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(142,7): error TS2322: Type '{ x: number; y: {}; }' is not assignable to type '{ x: number; y: string; }'. - Types of property 'y' are incompatible. - Type '{}' is not assignable to type 'string'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(147,7): error TS2322: Type '[{}, {}]' is not assignable to type '[number, string]'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(148,7): error TS2322: Type '[{}, {}]' is not assignable to type '[number, string]'. tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(152,5): error TS2564: Property 'payload' has no initializer and is not definitely assigned in the constructor. tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(166,5): error TS2564: Property 'test' has no initializer and is not definitely assigned in the constructor. tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(170,17): error TS2345: Argument of type 'true' is not assignable to parameter of type '{ a: string; b: number; }'. @@ -92,23 +60,14 @@ tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(237,9): e Type 'number' is not assignable to type 'string'. tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(261,19): error TS2345: Argument of type '4' is not assignable to parameter of type '5'. tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(286,8): error TS2345: Argument of type '4' is not assignable to parameter of type 'string'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(301,17): error TS2345: Argument of type '(tag: T, value: Q) => { tag: T; value: Q; }' is not assignable to parameter of type '(a: {}, b: {}) => { tag: string; value: {}; }'. - Types of parameters 'tag' and 'a' are incompatible. - Type '{}' is not assignable to type 'string'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(310,20): error TS2345: Argument of type '(x: number) => T' is not assignable to parameter of type '(b: {}) => {}'. - Types of parameters 'x' and 'b' are incompatible. - Type '{}' is not assignable to type 'number'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(287,19): error TS2345: Argument of type '4' is not assignable to parameter of type 'string'. +tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(305,18): error TS2345: Argument of type '5' is not assignable to parameter of type 'string'. tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(359,8): error TS2345: Argument of type '(x: number, y: string | number) => void' is not assignable to parameter of type '(a: string, b: string | number) => void'. Types of parameters 'x' and 'a' are incompatible. Type 'string' is not assignable to type 'number'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(365,8): error TS2345: Argument of type '(y: string | number) => void' is not assignable to parameter of type '(b: number | {}) => void'. - Types of parameters 'y' and 'b' are incompatible. - Type 'number | {}' is not assignable to type 'string | number'. - Type '{}' is not assignable to type 'string | number'. - Type '{}' is not assignable to type 'number'. -==== tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts (41 errors) ==== +==== tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts (30 errors) ==== export {} // Borrowed from @gcnew at https://gist.github.com/gcnew/ad833bfa376e4b70fc50a780e3b2d883 @@ -144,12 +103,6 @@ tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(365,8): e declare function lego1(x: A, l: List, y: A): A; declare function lego2(f: (l: List, x: D, y: D) => D): void; lego2(lego1); - ~~~~~ -!!! error TS2345: Argument of type '(x: A, l: List, y: A) => A' is not assignable to parameter of type '(l: List<{}>, x: {}, y: {}) => {}'. -!!! error TS2345: Types of parameters 'l' and 'x' are incompatible. -!!! error TS2345: Type '{}' is not assignable to type 'List<{}>'. -!!! error TS2345: Type '{}' is not assignable to type '{ kind: "cons"; val: {}; rest: List<{}>; }'. -!!! error TS2345: Property 'kind' is missing in type '{}'. declare function bombastic(f: (x: string, y: number) => R): R; declare function bombastic2(f: (x: string, y: number) => string): void; @@ -175,7 +128,7 @@ tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(365,8): e declare function id3(x: T, y: U, z: V): V; bombastic3(id3); // Should be error ~~~ -!!! error TS2345: Argument of type '(x: T, y: U, z: V) => V' is not assignable to parameter of type '(x: string, y: number, z: {}) => {}'. +!!! error TS2345: Argument of type '(x: T, y: U, z: V) => V' is not assignable to parameter of type '(x: string, y: number, z: string) => string'. !!! error TS2345: Types of parameters 'y' and 'y' are incompatible. !!! error TS2345: Type 'number' is not assignable to type 'string'. bombastic3(id3); // Should be error because of reason from bombastic(id2) @@ -273,35 +226,10 @@ tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(365,8): e declare function trans(f: (x: T) => string): number; // TODO: these should all be noImplicitAny / destructuring erros trans(({a}) => a); - ~~~~~~~~~~ -!!! error TS2345: Argument of type '({ a }: { a: any; }) => any' is not assignable to parameter of type '(x: {}) => string'. -!!! error TS2345: Types of parameters '__0' and 'x' are incompatible. -!!! error TS2345: Type '{}' is not assignable to type '{ a: any; }'. -!!! error TS2345: Property 'a' is missing in type '{}'. trans(([b,c]) => 'foo'); - ~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '([b, c]: [any, any]) => string' is not assignable to parameter of type '(x: {}) => string'. -!!! error TS2345: Types of parameters '__0' and 'x' are incompatible. -!!! error TS2345: Type '{}' is not assignable to type '[any, any]'. -!!! error TS2345: Property '0' is missing in type '{}'. trans(({d: [e,f]}) => 'foo'); - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '({ d: [e, f] }: { d: [any, any]; }) => string' is not assignable to parameter of type '(x: {}) => string'. -!!! error TS2345: Types of parameters '__0' and 'x' are incompatible. -!!! error TS2345: Type '{}' is not assignable to type '{ d: [any, any]; }'. -!!! error TS2345: Property 'd' is missing in type '{}'. trans(([{g},{h}]) => 'foo'); - ~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '([{ g }, { h }]: [{ g: any; }, { h: any; }]) => string' is not assignable to parameter of type '(x: {}) => string'. -!!! error TS2345: Types of parameters '__0' and 'x' are incompatible. -!!! error TS2345: Type '{}' is not assignable to type '[{ g: any; }, { h: any; }]'. -!!! error TS2345: Property '0' is missing in type '{}'. trans(({a, b = 10}) => a); - ~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '({ a, b }: { a: any; b?: number; }) => any' is not assignable to parameter of type '(x: {}) => string'. -!!! error TS2345: Types of parameters '__0' and 'x' are incompatible. -!!! error TS2345: Type '{}' is not assignable to type '{ a: any; b?: number; }'. -!!! error TS2345: Property 'a' is missing in type '{}'. declare function idCreator(f: (x: T|undefined) => T): T; const icn: number = idCreator(_ => 5); // ZZZ @@ -342,24 +270,13 @@ tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(365,8): e declare function botox(idX: (x: X) => X, idY: (y: Y) => Y): (x: X, y: Y) => [X, Y]; const xyPair: [number, string] = botox(id, id)(3, 'str'); - ~~~~~~ -!!! error TS2322: Type '[{}, {}]' is not assignable to type '[number, string]'. -!!! error TS2322: Type '{}' is not assignable to type 'number'. const testPair: { x: number, y: string } = pair(3)('str'); - ~~~~~~~~ -!!! error TS2322: Type '{ x: number; y: {}; }' is not assignable to type '{ x: number; y: string; }'. -!!! error TS2322: Types of property 'y' are incompatible. -!!! error TS2322: Type '{}' is not assignable to type 'string'. declare function botox2(idX: { a: (x: X) => X }, idY: { a: (y: Y) => Y }): (x: X, y: Y) => [X, Y]; const bottoxObj = { a: id }; const xyPair2: [number, string] = botox2(bottoxObj, bottoxObj)(3, 'str'); // ZZZ - ~~~~~~~ -!!! error TS2322: Type '[{}, {}]' is not assignable to type '[number, string]'. const xyPair3: [number, string] = botox2({ a: id }, { a: id })(3, 'str'); - ~~~~~~~ -!!! error TS2322: Type '[{}, {}]' is not assignable to type '[number, string]'. class GenericClass { @@ -527,6 +444,8 @@ tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(365,8): e ~ !!! error TS2345: Argument of type '4' is not assignable to parameter of type 'string'. flip(fbound)("4", 4) // Error + ~ +!!! error TS2345: Argument of type '4' is not assignable to parameter of type 'string'. function of2(one: a, two: b): [a, b] { return [one, two]; @@ -541,23 +460,17 @@ tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(365,8): e const f2 = flip(id); // (b: {}, a: T): T const f3 = flip(fconst); // (b: Y, a: X) => X const f4 = flip(tagged); // (b: Q, a: T) => { tag: T, value: Q } - ~~~~~~ -!!! error TS2345: Argument of type '(tag: T, value: Q) => { tag: T; value: Q; }' is not assignable to parameter of type '(a: {}, b: {}) => { tag: string; value: {}; }'. -!!! error TS2345: Types of parameters 'tag' and 'a' are incompatible. -!!! error TS2345: Type '{}' is not assignable to type 'string'. const v3 = f3(1, "qw") // `"qw"` const v4 = f3([], {}) // `{}` const v5 = f4(5, "hello"); // { tag: "hello", value: number } const v6 = f4(5, 5); // Error as expected + ~ +!!! error TS2345: Argument of type '5' is not assignable to parameter of type 'string'. declare function compose(f: (b: B) => C, g: (a: A) => B): (a: A) => C; declare const f: (x:number) => T; declare const g: (x:boolean) => number; const f5 = compose(f, g) // OUCH! this gets type `(a: boolean) => T` - ~ -!!! error TS2345: Argument of type '(x: number) => T' is not assignable to parameter of type '(b: {}) => {}'. -!!! error TS2345: Types of parameters 'x' and 'b' are incompatible. -!!! error TS2345: Type '{}' is not assignable to type 'number'. declare const g_2: (x: T) => boolean; declare const f_2: (x: boolean) => number; const f6 = compose(f_2, g_2) // (a: T) => number @@ -617,11 +530,5 @@ tests/cases/compiler/inferringGenericFunctionsFromGenericFunctions2.ts(365,8): e declare function uParam42(y: number|X): X; declare function uParam43(y: string|X): X; union4(uParam41, 4); // A = number, B = string, C = void - ~~~~~~~~ -!!! error TS2345: Argument of type '(y: string | number) => void' is not assignable to parameter of type '(b: number | {}) => void'. -!!! error TS2345: Types of parameters 'y' and 'b' are incompatible. -!!! error TS2345: Type 'number | {}' is not assignable to type 'string | number'. -!!! error TS2345: Type '{}' is not assignable to type 'string | number'. -!!! error TS2345: Type '{}' is not assignable to type 'number'. union4(uParam42, 4); // A = number, B = X, C = X union4(uParam43, 4); // A = number, B = string, C = number \ No newline at end of file diff --git a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.types b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.types index 456b8de8d2fd9..9d3711cc793e2 100644 --- a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.types +++ b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctions2.types @@ -145,8 +145,8 @@ declare const pair: (x: T) => (y: S) => { x: T; y: S; } >S : S const zr = zipWith([1, 2], ['a', 'b'], pair); ->zr : { x: number; y: {}; }[] ->zipWith([1, 2], ['a', 'b'], pair) : { x: number; y: {}; }[] +>zr : { x: number; y: string; }[] +>zipWith([1, 2], ['a', 'b'], pair) : { x: number; y: string; }[] >zipWith : (a: T[], b: S[], f: (x: T) => (y: S) => U) => U[] >[1, 2] : number[] >1 : 1 @@ -184,7 +184,7 @@ declare function lego2(f: (l: List, x: D, y: D) => D): void; >D : D lego2(lego1); ->lego2(lego1) : any +>lego2(lego1) : void >lego2 : (f: (l: List, x: D, y: D) => D) => void >lego1 : (x: A, l: List, y: A) => A @@ -545,14 +545,14 @@ declare function trans(f: (x: T) => string): number; // TODO: these should all be noImplicitAny / destructuring erros trans(({a}) => a); ->trans(({a}) => a) : any +>trans(({a}) => a) : number >trans : (f: (x: T) => string) => number >({a}) => a : ({ a }: { a: any; }) => any >a : any >a : any trans(([b,c]) => 'foo'); ->trans(([b,c]) => 'foo') : any +>trans(([b,c]) => 'foo') : number >trans : (f: (x: T) => string) => number >([b,c]) => 'foo' : ([b, c]: [any, any]) => string >b : any @@ -560,7 +560,7 @@ trans(([b,c]) => 'foo'); >'foo' : "foo" trans(({d: [e,f]}) => 'foo'); ->trans(({d: [e,f]}) => 'foo') : any +>trans(({d: [e,f]}) => 'foo') : number >trans : (f: (x: T) => string) => number >({d: [e,f]}) => 'foo' : ({ d: [e, f] }: { d: [any, any]; }) => string >d : any @@ -569,7 +569,7 @@ trans(({d: [e,f]}) => 'foo'); >'foo' : "foo" trans(([{g},{h}]) => 'foo'); ->trans(([{g},{h}]) => 'foo') : any +>trans(([{g},{h}]) => 'foo') : number >trans : (f: (x: T) => string) => number >([{g},{h}]) => 'foo' : ([{ g }, { h }]: [{ g: any; }, { h: any; }]) => string >g : any @@ -577,7 +577,7 @@ trans(([{g},{h}]) => 'foo'); >'foo' : "foo" trans(({a, b = 10}) => a); ->trans(({a, b = 10}) => a) : any +>trans(({a, b = 10}) => a) : number >trans : (f: (x: T) => string) => number >({a, b = 10}) => a : ({ a, b }: { a: any; b?: number; }) => any >a : any @@ -711,8 +711,8 @@ const a10: string[] = ["a", "b"]; >"b" : "b" const b10 = a10.map(f10); ->b10 : {}[] ->a10.map(f10) : {}[] +>b10 : string[] +>a10.map(f10) : string[] >a10.map : (callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[] >a10 : string[] >map : (callbackfn: (value: string, index: number, array: string[]) => U, thisArg?: any) => U[] @@ -739,8 +739,8 @@ declare function botox(idX: (x: X) => X, idY: (y: Y) => Y): (x: X, y: Y) = const xyPair: [number, string] = botox(id, id)(3, 'str'); >xyPair : [number, string] ->botox(id, id)(3, 'str') : [{}, {}] ->botox(id, id) : (x: {}, y: {}) => [{}, {}] +>botox(id, id)(3, 'str') : [number, string] +>botox(id, id) : (x: X, y: Y) => [X, Y] >botox : (idX: (x: X) => X, idY: (y: Y) => Y) => (x: X, y: Y) => [X, Y] >id : (x: I) => I >id : (x: I) => I @@ -751,8 +751,8 @@ const testPair: { x: number, y: string } = pair(3)('str'); >testPair : { x: number; y: string; } >x : number >y : string ->pair(3)('str') : { x: number; y: {}; } ->pair(3) : (y: {}) => { x: number; y: {}; } +>pair(3)('str') : { x: number; y: string; } +>pair(3) : (y: S) => { x: number; y: S; } >pair : (x: T) => (y: S) => { x: T; y: S; } >3 : 3 >'str' : "str" @@ -786,8 +786,8 @@ const bottoxObj = { a: id }; const xyPair2: [number, string] = botox2(bottoxObj, bottoxObj)(3, 'str'); // ZZZ >xyPair2 : [number, string] ->botox2(bottoxObj, bottoxObj)(3, 'str') : [{}, {}] ->botox2(bottoxObj, bottoxObj) : (x: {}, y: {}) => [{}, {}] +>botox2(bottoxObj, bottoxObj)(3, 'str') : [number, string] +>botox2(bottoxObj, bottoxObj) : (x: X, y: Y) => [X, Y] >botox2 : (idX: { a: (x: X) => X; }, idY: { a: (y: Y) => Y; }) => (x: X, y: Y) => [X, Y] >bottoxObj : { a: (x: I) => I; } >bottoxObj : { a: (x: I) => I; } @@ -796,8 +796,8 @@ const xyPair2: [number, string] = botox2(bottoxObj, bottoxObj)(3, 'str'); // ZZZ const xyPair3: [number, string] = botox2({ a: id }, { a: id })(3, 'str'); >xyPair3 : [number, string] ->botox2({ a: id }, { a: id })(3, 'str') : [{}, {}] ->botox2({ a: id }, { a: id }) : (x: {}, y: {}) => [{}, {}] +>botox2({ a: id }, { a: id })(3, 'str') : [number, string] +>botox2({ a: id }, { a: id }) : (x: X, y: Y) => [X, Y] >botox2 : (idX: { a: (x: X) => X; }, idY: { a: (y: Y) => Y; }) => (x: X, y: Y) => [X, Y] >{ a: id } : { a: (x: I) => I; } >a : (x: I) => I @@ -1368,8 +1368,8 @@ function foo2(x: T, cb: new(a: T) => U) { } var r4b = foo2(1, a); // number ->r4b : {} ->foo2(1, a) : {} +>r4b : number +>foo2(1, a) : 1 >foo2 : (x: T, cb: new (a: T) => U) => U >1 : 1 >a : new (x: T) => T @@ -1504,8 +1504,8 @@ fbound(4, 4).tag; // 4 (better) or number >tag : number flip(fbound)(4, 4) // OK ->flip(fbound)(4, 4) : { tag: {}; value: {}; } ->flip(fbound) : (b: {}, a: {}) => { tag: {}; value: {}; } +>flip(fbound)(4, 4) : { tag: number; value: number; } +>flip(fbound) : (b: B, a: B) => { tag: B; value: B; } >flip : (f: (a: A, b: B) => R) => (b: B, a: A) => R >fbound : (tag: T, value: Q) => { tag: T; value: Q; } >4 : 4 @@ -1518,8 +1518,8 @@ fbound(4, "4"); // Error >"4" : "4" flip(fbound)("4", 4) // Error ->flip(fbound)("4", 4) : { tag: {}; value: {}; } ->flip(fbound) : (b: {}, a: {}) => { tag: {}; value: {}; } +>flip(fbound)("4", 4) : any +>flip(fbound) : (b: B, a: B) => { tag: B; value: B; } >flip : (f: (a: A, b: B) => R) => (b: B, a: A) => R >fbound : (tag: T, value: Q) => { tag: T; value: Q; } >"4" : "4" @@ -1542,8 +1542,8 @@ function of2(one: a, two: b): [a, b] { >two : b } const flipped = flip(of2); ->flipped : (b: {}, a: {}) => [{}, {}] ->flip(of2) : (b: {}, a: {}) => [{}, {}] +>flipped : (b: B, a: A) => [A, B] +>flip(of2) : (b: B, a: A) => [A, B] >flip : (f: (a: A, b: B) => R) => (b: B, a: A) => R >of2 : (one: a, two: b) => [a, b] @@ -1571,48 +1571,48 @@ const v2 = id(id)(3); // `3` // working now const f2 = flip(id); // (b: {}, a: T): T ->f2 : (b: {}, a: {}) => {} ->flip(id) : (b: {}, a: {}) => {} +>f2 : (b: B, a: A) => A +>flip(id) : (b: B, a: A) => A >flip : (f: (a: A, b: B) => R) => (b: B, a: A) => R >id : (x: I) => I const f3 = flip(fconst); // (b: Y, a: X) => X ->f3 : (b: {}, a: {}) => {} ->flip(fconst) : (b: {}, a: {}) => {} +>f3 : (b: B, a: A) => A +>flip(fconst) : (b: B, a: A) => A >flip : (f: (a: A, b: B) => R) => (b: B, a: A) => R >fconst : (x: X, y: Y) => X const f4 = flip(tagged); // (b: Q, a: T) => { tag: T, value: Q } ->f4 : any ->flip(tagged) : any +>f4 : (b: B, a: string) => { tag: string; value: B; } +>flip(tagged) : (b: B, a: string) => { tag: string; value: B; } >flip : (f: (a: A, b: B) => R) => (b: B, a: A) => R >tagged : (tag: T, value: Q) => { tag: T; value: Q; } const v3 = f3(1, "qw") // `"qw"` ->v3 : {} ->f3(1, "qw") : {} ->f3 : (b: {}, a: {}) => {} +>v3 : "qw" +>f3(1, "qw") : "qw" +>f3 : (b: B, a: A) => A >1 : 1 >"qw" : "qw" const v4 = f3([], {}) // `{}` >v4 : {} >f3([], {}) : {} ->f3 : (b: {}, a: {}) => {} +>f3 : (b: B, a: A) => A >[] : never[] >{} : {} const v5 = f4(5, "hello"); // { tag: "hello", value: number } ->v5 : any ->f4(5, "hello") : any ->f4 : any +>v5 : { tag: string; value: number; } +>f4(5, "hello") : { tag: string; value: number; } +>f4 : (b: B, a: string) => { tag: string; value: B; } >5 : 5 >"hello" : "hello" const v6 = f4(5, 5); // Error as expected >v6 : any >f4(5, 5) : any ->f4 : any +>f4 : (b: B, a: string) => { tag: string; value: B; } >5 : 5 >5 : 5 @@ -1644,8 +1644,8 @@ declare const g: (x:boolean) => number; >x : boolean const f5 = compose(f, g) // OUCH! this gets type `(a: boolean) => T` ->f5 : any ->compose(f, g) : any +>f5 : (a: boolean) => T +>compose(f, g) : (a: boolean) => T >compose : (f: (b: B) => C, g: (a: A) => B) => (a: A) => C >f : (x: number) => T >g : (x: boolean) => number @@ -1661,22 +1661,22 @@ declare const f_2: (x: boolean) => number; >x : boolean const f6 = compose(f_2, g_2) // (a: T) => number ->f6 : (a: {}) => number ->compose(f_2, g_2) : (a: {}) => number +>f6 : (a: A) => number +>compose(f_2, g_2) : (a: A) => number >compose : (f: (b: B) => C, g: (a: A) => B) => (a: A) => C >f_2 : (x: boolean) => number >g_2 : (x: T) => boolean const f7 = compose(id, x => String(x)) // (a: {}) => string ->f7 : (a: {}) => {} ->compose(id, x => String(x)) : (a: {}) => {} +>f7 : (a: A) => string +>compose(id, x => String(x)) : (a: A) => string >compose : (f: (b: B) => C, g: (a: A) => B) => (a: A) => C >id : (x: I) => I ->x => String(x) : (x: {}) => string ->x : {} +>x => String(x) : (x: A) => string +>x : A >String(x) : string >String : StringConstructor ->x : {} +>x : A declare function h(f: (x: number) => R): R; >h : (f: (x: number) => R) => R @@ -1887,7 +1887,7 @@ declare function uParam33(x: string, y: number|string): void; >y : string | number union3(uParam31); // error; A,X = [number, string] ->union3(uParam31) : {} +>union3(uParam31) : string | number | {} >union3 : (f: (a: string | A, b: number | A) => B) => B >uParam31 : (x: number | X, y: string | X) => X @@ -1934,19 +1934,19 @@ declare function uParam43(y: string|X): X; >X : X union4(uParam41, 4); // A = number, B = string, C = void ->union4(uParam41, 4) : any +>union4(uParam41, 4) : void >union4 : (f: (b: A | B) => C, a: A) => C >uParam41 : (y: string | number) => void >4 : 4 union4(uParam42, 4); // A = number, B = X, C = X ->union4(uParam42, 4) : {} +>union4(uParam42, 4) : {} | 4 >union4 : (f: (b: A | B) => C, a: A) => C >uParam42 : (y: number | X) => X >4 : 4 union4(uParam43, 4); // A = number, B = string, C = number ->union4(uParam43, 4) : {} +>union4(uParam43, 4) : {} | 4 >union4 : (f: (b: A | B) => C, a: A) => C >uParam43 : (y: string | X) => X >4 : 4 diff --git a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.errors.txt b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.errors.txt deleted file mode 100644 index 70cbe902d4adb..0000000000000 --- a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.errors.txt +++ /dev/null @@ -1,192 +0,0 @@ -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(17,11): error TS2322: Type '(a2: {}) => {}' is not assignable to type '(u: U) => U'. - Type '{}' is not assignable to type 'U'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(19,11): error TS2322: Type '{}' is not assignable to type 'string'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(24,11): error TS2322: Type '(a2: {}) => {}[]' is not assignable to type '(u: U) => U[]'. - Type '{}[]' is not assignable to type 'U[]'. - Type '{}' is not assignable to type 'U'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(26,11): error TS2322: Type '{}[]' is not assignable to type 'string[]'. - Type '{}' is not assignable to type 'string'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(31,11): error TS2322: Type '(a2: {}) => {}[]' is not assignable to type '(u: U) => U[]'. - Type '{}[]' is not assignable to type 'U[]'. - Type '{}' is not assignable to type 'U'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(33,11): error TS2322: Type '{}[]' is not assignable to type 'string[]'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(38,11): error TS2322: Type '(a2: {}) => { boxed: {}[]; }' is not assignable to type '(u: U) => { boxed: U[]; }'. - Type '{ boxed: {}[]; }' is not assignable to type '{ boxed: U[]; }'. - Types of property 'boxed' are incompatible. - Type '{}[]' is not assignable to type 'U[]'. - Type '{}' is not assignable to type 'U'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(40,11): error TS2322: Type '{ boxed: {}[]; }' is not assignable to type '{ boxed: string[]; }'. - Types of property 'boxed' are incompatible. - Type '{}[]' is not assignable to type 'string[]'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(45,11): error TS2322: Type '(d2: {}) => [{}, { boxed: string; }]' is not assignable to type '(u: U) => [U, { boxed: string; }]'. - Type '[{}, { boxed: string; }]' is not assignable to type '[U, { boxed: string; }]'. - Type '{}' is not assignable to type 'U'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(47,11): error TS2322: Type '[{}, { boxed: string; }]' is not assignable to type '[number, { boxed: string; }]'. - Type '{}' is not assignable to type 'number'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(56,36): error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(b1: {}) => string'. - Types of parameters 'x' and 'b1' are incompatible. - Type '{}' is not assignable to type 'string'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(63,37): error TS2345: Argument of type '(x2: string) => string[]' is not assignable to parameter of type '(b1: {}) => string[]'. - Types of parameters 'x2' and 'b1' are incompatible. - Type '{}' is not assignable to type 'string'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(70,37): error TS2345: Argument of type '(x2: string) => string' is not assignable to parameter of type '(b1: {}[]) => string'. - Types of parameters 'x2' and 'b1' are incompatible. - Type '{}[]' is not assignable to type 'string'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(77,37): error TS2345: Argument of type '(x2: string) => { boxed: string; }' is not assignable to parameter of type '(b1: {}[]) => { boxed: string; }'. - Types of parameters 'x2' and 'b1' are incompatible. - Type '{}[]' is not assignable to type 'string'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(85,11): error TS2322: Type '(d2: {}) => [{}, { boxed: string; }]' is not assignable to type '(u: U) => [U, { boxed: string; }]'. - Type '[{}, { boxed: string; }]' is not assignable to type '[U, { boxed: string; }]'. - Type '{}' is not assignable to type 'U'. -tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts(87,11): error TS2322: Type '[{}, { boxed: string; }]' is not assignable to type '[number, { boxed: string; }]'. - Type '{}' is not assignable to type 'number'. - - -==== tests/cases/compiler/inferringGenericFunctionsFromGenericFunctionsContexual.ts (16 errors) ==== - export {} - - declare function identity1(f: (t: T) => U): (t2: T) => U - const id1 = identity1(x => x) - - - declare function identity2(f: (t: T) => U): (t2: T) => U - const id2 = identity2(x => x) - - - // compose is just something I put in to make sure the contextual types handle multiple signatures. - declare function compose(f: (d: D) => E, g: (e: E) => F): (d2: D) => [D, F]; - declare function compose(f: (a1: A) => B, g: (b1: B) => C): (a2: A) => C; - - { - let composed1 = compose(x => x, x2 => x2) - const expectedComposed1: (u: U) => U = composed1; - ~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '(a2: {}) => {}' is not assignable to type '(u: U) => U'. -!!! error TS2322: Type '{}' is not assignable to type 'U'. - const callComposed1 = composed1("test"); - const expectedCallComposed1 : string = callComposed1; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '{}' is not assignable to type 'string'. - } - - { - let composed2 = compose(x => x, x2 => [x2]) - const expectedComposed2: (u: U) => U[] = composed2; - ~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '(a2: {}) => {}[]' is not assignable to type '(u: U) => U[]'. -!!! error TS2322: Type '{}[]' is not assignable to type 'U[]'. -!!! error TS2322: Type '{}' is not assignable to type 'U'. - const callComposed2 = composed2("test"); - const expectedCallComposed2: string[] = callComposed2; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '{}[]' is not assignable to type 'string[]'. -!!! error TS2322: Type '{}' is not assignable to type 'string'. - } - - { - let composed3 = compose(x => [x], x2 => x2) - const expectedComposed3: (u: U) => U[] = composed3; - ~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '(a2: {}) => {}[]' is not assignable to type '(u: U) => U[]'. -!!! error TS2322: Type '{}[]' is not assignable to type 'U[]'. -!!! error TS2322: Type '{}' is not assignable to type 'U'. - const callComposed3 = composed3("test"); - const expectedCallComposed3 : string[] = callComposed3; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '{}[]' is not assignable to type 'string[]'. - } - - { - let composed4 = compose(x => [x], x2 => ({ boxed: x2 })); - const expectedComposed4: (u: U) => {boxed: U[]} = composed4; - ~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '(a2: {}) => { boxed: {}[]; }' is not assignable to type '(u: U) => { boxed: U[]; }'. -!!! error TS2322: Type '{ boxed: {}[]; }' is not assignable to type '{ boxed: U[]; }'. -!!! error TS2322: Types of property 'boxed' are incompatible. -!!! error TS2322: Type '{}[]' is not assignable to type 'U[]'. -!!! error TS2322: Type '{}' is not assignable to type 'U'. - const callComposed4 = composed4("test"); - const expectedCallComposed4 : {boxed: string[]} = callComposed4; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '{ boxed: {}[]; }' is not assignable to type '{ boxed: string[]; }'. -!!! error TS2322: Types of property 'boxed' are incompatible. -!!! error TS2322: Type '{}[]' is not assignable to type 'string[]'. - } - - { - let composed5 = compose(x => "" + x, x2 => ({ boxed: x2 })); - const expectedComposed5: (u: U) => [U, {boxed: string}] = composed5; - ~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '(d2: {}) => [{}, { boxed: string; }]' is not assignable to type '(u: U) => [U, { boxed: string; }]'. -!!! error TS2322: Type '[{}, { boxed: string; }]' is not assignable to type '[U, { boxed: string; }]'. -!!! error TS2322: Type '{}' is not assignable to type 'U'. - const callComposed5 = composed5(123456); - const expectedCallComposed5 : [number, {boxed: string}] = callComposed5; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '[{}, { boxed: string; }]' is not assignable to type '[number, { boxed: string; }]'. -!!! error TS2322: Type '{}' is not assignable to type 'number'. - } - - - declare function composeReverse(g: (e: E) => F, f: (d: D) => E): (d2: D) => [D, F]; - declare function composeReverse(g: (b1: B) => C, f: (a1: A) => B): (a2: A) => C; - - - { - let composed1 = composeReverse(x => x, x2 => x2) - ~~~~~~ -!!! error TS2345: Argument of type '(x: string) => string' is not assignable to parameter of type '(b1: {}) => string'. -!!! error TS2345: Types of parameters 'x' and 'b1' are incompatible. -!!! error TS2345: Type '{}' is not assignable to type 'string'. - const expectedComposed1: (u: U) => U = composed1; - const callComposed1 = composed1("test"); - const expectedCallComposed1 : string = callComposed1; - } - - { - let composed2 = composeReverse( x2 => [x2], x => x) - ~~~~~~~~~~ -!!! error TS2345: Argument of type '(x2: string) => string[]' is not assignable to parameter of type '(b1: {}) => string[]'. -!!! error TS2345: Types of parameters 'x2' and 'b1' are incompatible. -!!! error TS2345: Type '{}' is not assignable to type 'string'. - const expectedComposed2: (u: U) => U[] = composed2; - const callComposed2 = composed2("test"); - const expectedCallComposed2: string[] = callComposed2; - } - - { - let composed3 = composeReverse( x2 => x2, x => [x]) - ~~~~~~~~ -!!! error TS2345: Argument of type '(x2: string) => string' is not assignable to parameter of type '(b1: {}[]) => string'. -!!! error TS2345: Types of parameters 'x2' and 'b1' are incompatible. -!!! error TS2345: Type '{}[]' is not assignable to type 'string'. - const expectedComposed3: (u: U) => U[] = composed3; - const callComposed3 = composed3("test"); - const expectedCallComposed3 : string[] = callComposed3; - } - - { - let composed4 = composeReverse( x2 => ({ boxed: x2 }), x => [x]); - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x2: string) => { boxed: string; }' is not assignable to parameter of type '(b1: {}[]) => { boxed: string; }'. -!!! error TS2345: Types of parameters 'x2' and 'b1' are incompatible. -!!! error TS2345: Type '{}[]' is not assignable to type 'string'. - const expectedComposed4: (u: U) => {boxed: U[]} = composed4; - const callComposed4 = composed4("test"); - const expectedCallComposed4 : {boxed: string[]} = callComposed4; - } - - { - let composed5 = composeReverse( x2 => ({ boxed: x2 }), x => "" + x); - const expectedComposed5: (u: U) => [U, {boxed: string}] = composed5; - ~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '(d2: {}) => [{}, { boxed: string; }]' is not assignable to type '(u: U) => [U, { boxed: string; }]'. -!!! error TS2322: Type '[{}, { boxed: string; }]' is not assignable to type '[U, { boxed: string; }]'. -!!! error TS2322: Type '{}' is not assignable to type 'U'. - const callComposed5 = composed5(123456); - const expectedCallComposed5 : [number, {boxed: string}] = callComposed5; - ~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2322: Type '[{}, { boxed: string; }]' is not assignable to type '[number, { boxed: string; }]'. -!!! error TS2322: Type '{}' is not assignable to type 'number'. - } - \ No newline at end of file diff --git a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.types b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.types index 84217860e7ee3..c2faace0023a0 100644 --- a/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.types +++ b/tests/baselines/reference/inferringGenericFunctionsFromGenericFunctionsContexual.types @@ -14,12 +14,12 @@ declare function identity1(f: (t: T) => U): (t2: T) => U >U : U const id1 = identity1(x => x) ->id1 : (t2: {}) => {} ->identity1(x => x) : (t2: {}) => {} +>id1 : (t2: T) => T +>identity1(x => x) : (t2: T) => T >identity1 : (f: (t: T) => U) => (t2: T) => U ->x => x : (x: {}) => {} ->x : {} ->x : {} +>x => x : (x: T) => T +>x : T +>x : T declare function identity2(f: (t: T) => U): (t2: T) => U @@ -35,12 +35,12 @@ declare function identity2(f: (t: T) => U): (t2: T) => U >U : U const id2 = identity2(x => x) ->id2 : (t2: number) => number ->identity2(x => x) : (t2: number) => number +>id2 : (t2: T) => T +>identity2(x => x) : (t2: T) => T >identity2 : (f: (t: T) => U) => (t2: T) => U ->x => x : (x: number) => number ->x : number ->x : number +>x => x : (x: T) => T +>x : T +>x : T // compose is just something I put in to make sure the contextual types handle multiple signatures. @@ -81,15 +81,15 @@ declare function compose(f: (a1: A) => B, g: (b1: B) => C): (a2: A) => { let composed1 = compose(x => x, x2 => x2) ->composed1 : (a2: {}) => {} ->compose(x => x, x2 => x2) : (a2: {}) => {} +>composed1 : (a2: A) => A +>compose(x => x, x2 => x2) : (a2: A) => A >compose : { (f: (d: D) => E, g: (e: E) => F): (d2: D) => [D, F]; (f: (a1: A) => B, g: (b1: B) => C): (a2: A) => C; } ->x => x : (x: {}) => {} ->x : {} ->x : {} ->x2 => x2 : (x2: {}) => {} ->x2 : {} ->x2 : {} +>x => x : (x: A) => A +>x : A +>x : A +>x2 => x2 : (x2: A) => A +>x2 : A +>x2 : A const expectedComposed1: (u: U) => U = composed1; >expectedComposed1 : (u: U) => U @@ -97,31 +97,31 @@ declare function compose(f: (a1: A) => B, g: (b1: B) => C): (a2: A) => >u : U >U : U >U : U ->composed1 : (a2: {}) => {} +>composed1 : (a2: A) => A const callComposed1 = composed1("test"); ->callComposed1 : {} ->composed1("test") : {} ->composed1 : (a2: {}) => {} +>callComposed1 : "test" +>composed1("test") : "test" +>composed1 : (a2: A) => A >"test" : "test" const expectedCallComposed1 : string = callComposed1; >expectedCallComposed1 : string ->callComposed1 : {} +>callComposed1 : "test" } { let composed2 = compose(x => x, x2 => [x2]) ->composed2 : (a2: {}) => {}[] ->compose(x => x, x2 => [x2]) : (a2: {}) => {}[] +>composed2 : (a2: A) => A[] +>compose(x => x, x2 => [x2]) : (a2: A) => A[] >compose : { (f: (d: D) => E, g: (e: E) => F): (d2: D) => [D, F]; (f: (a1: A) => B, g: (b1: B) => C): (a2: A) => C; } ->x => x : (x: {}) => {} ->x : {} ->x : {} ->x2 => [x2] : (x2: {}) => {}[] ->x2 : {} ->[x2] : {}[] ->x2 : {} +>x => x : (x: A) => A +>x : A +>x : A +>x2 => [x2] : (x2: A) => A[] +>x2 : A +>[x2] : A[] +>x2 : A const expectedComposed2: (u: U) => U[] = composed2; >expectedComposed2 : (u: U) => U[] @@ -129,31 +129,31 @@ declare function compose(f: (a1: A) => B, g: (b1: B) => C): (a2: A) => >u : U >U : U >U : U ->composed2 : (a2: {}) => {}[] +>composed2 : (a2: A) => A[] const callComposed2 = composed2("test"); ->callComposed2 : {}[] ->composed2("test") : {}[] ->composed2 : (a2: {}) => {}[] +>callComposed2 : string[] +>composed2("test") : string[] +>composed2 : (a2: A) => A[] >"test" : "test" const expectedCallComposed2: string[] = callComposed2; >expectedCallComposed2 : string[] ->callComposed2 : {}[] +>callComposed2 : string[] } { let composed3 = compose(x => [x], x2 => x2) ->composed3 : (a2: {}) => {}[] ->compose(x => [x], x2 => x2) : (a2: {}) => {}[] +>composed3 : (a2: A) => A[] +>compose(x => [x], x2 => x2) : (a2: A) => A[] >compose : { (f: (d: D) => E, g: (e: E) => F): (d2: D) => [D, F]; (f: (a1: A) => B, g: (b1: B) => C): (a2: A) => C; } ->x => [x] : (x: {}) => {}[] ->x : {} ->[x] : {}[] ->x : {} ->x2 => x2 : (x2: {}[]) => {}[] ->x2 : {}[] ->x2 : {}[] +>x => [x] : (x: A) => A[] +>x : A +>[x] : A[] +>x : A +>x2 => x2 : (x2: A[]) => A[] +>x2 : A[] +>x2 : A[] const expectedComposed3: (u: U) => U[] = composed3; >expectedComposed3 : (u: U) => U[] @@ -161,34 +161,34 @@ declare function compose(f: (a1: A) => B, g: (b1: B) => C): (a2: A) => >u : U >U : U >U : U ->composed3 : (a2: {}) => {}[] +>composed3 : (a2: A) => A[] const callComposed3 = composed3("test"); ->callComposed3 : {}[] ->composed3("test") : {}[] ->composed3 : (a2: {}) => {}[] +>callComposed3 : string[] +>composed3("test") : string[] +>composed3 : (a2: A) => A[] >"test" : "test" const expectedCallComposed3 : string[] = callComposed3; >expectedCallComposed3 : string[] ->callComposed3 : {}[] +>callComposed3 : string[] } { let composed4 = compose(x => [x], x2 => ({ boxed: x2 })); ->composed4 : (a2: {}) => { boxed: {}[]; } ->compose(x => [x], x2 => ({ boxed: x2 })) : (a2: {}) => { boxed: {}[]; } +>composed4 : (a2: A) => { boxed: A[]; } +>compose(x => [x], x2 => ({ boxed: x2 })) : (a2: A) => { boxed: A[]; } >compose : { (f: (d: D) => E, g: (e: E) => F): (d2: D) => [D, F]; (f: (a1: A) => B, g: (b1: B) => C): (a2: A) => C; } ->x => [x] : (x: {}) => {}[] ->x : {} ->[x] : {}[] ->x : {} ->x2 => ({ boxed: x2 }) : (x2: {}[]) => { boxed: {}[]; } ->x2 : {}[] ->({ boxed: x2 }) : { boxed: {}[]; } ->{ boxed: x2 } : { boxed: {}[]; } ->boxed : {}[] ->x2 : {}[] +>x => [x] : (x: A) => A[] +>x : A +>[x] : A[] +>x : A +>x2 => ({ boxed: x2 }) : (x2: A[]) => { boxed: A[]; } +>x2 : A[] +>({ boxed: x2 }) : { boxed: A[]; } +>{ boxed: x2 } : { boxed: A[]; } +>boxed : A[] +>x2 : A[] const expectedComposed4: (u: U) => {boxed: U[]} = composed4; >expectedComposed4 : (u: U) => { boxed: U[]; } @@ -197,30 +197,30 @@ declare function compose(f: (a1: A) => B, g: (b1: B) => C): (a2: A) => >U : U >boxed : U[] >U : U ->composed4 : (a2: {}) => { boxed: {}[]; } +>composed4 : (a2: A) => { boxed: A[]; } const callComposed4 = composed4("test"); ->callComposed4 : { boxed: {}[]; } ->composed4("test") : { boxed: {}[]; } ->composed4 : (a2: {}) => { boxed: {}[]; } +>callComposed4 : { boxed: string[]; } +>composed4("test") : { boxed: string[]; } +>composed4 : (a2: A) => { boxed: A[]; } >"test" : "test" const expectedCallComposed4 : {boxed: string[]} = callComposed4; >expectedCallComposed4 : { boxed: string[]; } >boxed : string[] ->callComposed4 : { boxed: {}[]; } +>callComposed4 : { boxed: string[]; } } { let composed5 = compose(x => "" + x, x2 => ({ boxed: x2 })); ->composed5 : (d2: {}) => [{}, { boxed: string; }] ->compose(x => "" + x, x2 => ({ boxed: x2 })) : (d2: {}) => [{}, { boxed: string; }] +>composed5 : (d2: D) => [D, { boxed: string; }] +>compose(x => "" + x, x2 => ({ boxed: x2 })) : (d2: D) => [D, { boxed: string; }] >compose : { (f: (d: D) => E, g: (e: E) => F): (d2: D) => [D, F]; (f: (a1: A) => B, g: (b1: B) => C): (a2: A) => C; } ->x => "" + x : (x: {}) => string ->x : {} +>x => "" + x : (x: D) => string +>x : D >"" + x : string >"" : "" ->x : {} +>x : D >x2 => ({ boxed: x2 }) : (x2: string) => { boxed: string; } >x2 : string >({ boxed: x2 }) : { boxed: string; } @@ -235,18 +235,18 @@ declare function compose(f: (a1: A) => B, g: (b1: B) => C): (a2: A) => >U : U >U : U >boxed : string ->composed5 : (d2: {}) => [{}, { boxed: string; }] +>composed5 : (d2: D) => [D, { boxed: string; }] const callComposed5 = composed5(123456); ->callComposed5 : [{}, { boxed: string; }] ->composed5(123456) : [{}, { boxed: string; }] ->composed5 : (d2: {}) => [{}, { boxed: string; }] +>callComposed5 : [number, { boxed: string; }] +>composed5(123456) : [number, { boxed: string; }] +>composed5 : (d2: D) => [D, { boxed: string; }] >123456 : 123456 const expectedCallComposed5 : [number, {boxed: string}] = callComposed5; >expectedCallComposed5 : [number, { boxed: string; }] >boxed : string ->callComposed5 : [{}, { boxed: string; }] +>callComposed5 : [number, { boxed: string; }] } @@ -288,15 +288,15 @@ declare function composeReverse(g: (b1: B) => C, f: (a1: A) => B): (a2: { let composed1 = composeReverse(x => x, x2 => x2) ->composed1 : any ->composeReverse(x => x, x2 => x2) : any +>composed1 : (a2: A) => A +>composeReverse(x => x, x2 => x2) : (a2: A) => A >composeReverse : { (g: (e: E) => F, f: (d: D) => E): (d2: D) => [D, F]; (g: (b1: B) => C, f: (a1: A) => B): (a2: A) => C; } ->x => x : (x: string) => string ->x : string ->x : string ->x2 => x2 : (x2: {}) => {} ->x2 : {} ->x2 : {} +>x => x : (x: B) => B +>x : B +>x : B +>x2 => x2 : (x2: A) => A +>x2 : A +>x2 : A const expectedComposed1: (u: U) => U = composed1; >expectedComposed1 : (u: U) => U @@ -304,31 +304,31 @@ declare function composeReverse(g: (b1: B) => C, f: (a1: A) => B): (a2: >u : U >U : U >U : U ->composed1 : any +>composed1 : (a2: A) => A const callComposed1 = composed1("test"); ->callComposed1 : any ->composed1("test") : any ->composed1 : any +>callComposed1 : "test" +>composed1("test") : "test" +>composed1 : (a2: A) => A >"test" : "test" const expectedCallComposed1 : string = callComposed1; >expectedCallComposed1 : string ->callComposed1 : any +>callComposed1 : "test" } { let composed2 = composeReverse( x2 => [x2], x => x) ->composed2 : any ->composeReverse( x2 => [x2], x => x) : any +>composed2 : (a2: A) => A[] +>composeReverse( x2 => [x2], x => x) : (a2: A) => A[] >composeReverse : { (g: (e: E) => F, f: (d: D) => E): (d2: D) => [D, F]; (g: (b1: B) => C, f: (a1: A) => B): (a2: A) => C; } ->x2 => [x2] : (x2: string) => string[] ->x2 : string ->[x2] : string[] ->x2 : string ->x => x : (x: {}) => {} ->x : {} ->x : {} +>x2 => [x2] : (x2: B) => B[] +>x2 : B +>[x2] : B[] +>x2 : B +>x => x : (x: A) => A +>x : A +>x : A const expectedComposed2: (u: U) => U[] = composed2; >expectedComposed2 : (u: U) => U[] @@ -336,31 +336,31 @@ declare function composeReverse(g: (b1: B) => C, f: (a1: A) => B): (a2: >u : U >U : U >U : U ->composed2 : any +>composed2 : (a2: A) => A[] const callComposed2 = composed2("test"); ->callComposed2 : any ->composed2("test") : any ->composed2 : any +>callComposed2 : string[] +>composed2("test") : string[] +>composed2 : (a2: A) => A[] >"test" : "test" const expectedCallComposed2: string[] = callComposed2; >expectedCallComposed2 : string[] ->callComposed2 : any +>callComposed2 : string[] } { let composed3 = composeReverse( x2 => x2, x => [x]) ->composed3 : any ->composeReverse( x2 => x2, x => [x]) : any +>composed3 : (a2: A) => A[] +>composeReverse( x2 => x2, x => [x]) : (a2: A) => A[] >composeReverse : { (g: (e: E) => F, f: (d: D) => E): (d2: D) => [D, F]; (g: (b1: B) => C, f: (a1: A) => B): (a2: A) => C; } ->x2 => x2 : (x2: string) => string ->x2 : string ->x2 : string ->x => [x] : (x: {}) => {}[] ->x : {} ->[x] : {}[] ->x : {} +>x2 => x2 : (x2: B) => B +>x2 : B +>x2 : B +>x => [x] : (x: A) => A[] +>x : A +>[x] : A[] +>x : A const expectedComposed3: (u: U) => U[] = composed3; >expectedComposed3 : (u: U) => U[] @@ -368,34 +368,34 @@ declare function composeReverse(g: (b1: B) => C, f: (a1: A) => B): (a2: >u : U >U : U >U : U ->composed3 : any +>composed3 : (a2: A) => A[] const callComposed3 = composed3("test"); ->callComposed3 : any ->composed3("test") : any ->composed3 : any +>callComposed3 : string[] +>composed3("test") : string[] +>composed3 : (a2: A) => A[] >"test" : "test" const expectedCallComposed3 : string[] = callComposed3; >expectedCallComposed3 : string[] ->callComposed3 : any +>callComposed3 : string[] } { let composed4 = composeReverse( x2 => ({ boxed: x2 }), x => [x]); ->composed4 : any ->composeReverse( x2 => ({ boxed: x2 }), x => [x]) : any +>composed4 : (a2: A) => { boxed: A[]; } +>composeReverse( x2 => ({ boxed: x2 }), x => [x]) : (a2: A) => { boxed: A[]; } >composeReverse : { (g: (e: E) => F, f: (d: D) => E): (d2: D) => [D, F]; (g: (b1: B) => C, f: (a1: A) => B): (a2: A) => C; } ->x2 => ({ boxed: x2 }) : (x2: string) => { boxed: string; } ->x2 : string ->({ boxed: x2 }) : { boxed: string; } ->{ boxed: x2 } : { boxed: string; } ->boxed : string ->x2 : string ->x => [x] : (x: {}) => {}[] ->x : {} ->[x] : {}[] ->x : {} +>x2 => ({ boxed: x2 }) : (x2: B) => { boxed: B; } +>x2 : B +>({ boxed: x2 }) : { boxed: B; } +>{ boxed: x2 } : { boxed: B; } +>boxed : B +>x2 : B +>x => [x] : (x: A) => A[] +>x : A +>[x] : A[] +>x : A const expectedComposed4: (u: U) => {boxed: U[]} = composed4; >expectedComposed4 : (u: U) => { boxed: U[]; } @@ -404,36 +404,36 @@ declare function composeReverse(g: (b1: B) => C, f: (a1: A) => B): (a2: >U : U >boxed : U[] >U : U ->composed4 : any +>composed4 : (a2: A) => { boxed: A[]; } const callComposed4 = composed4("test"); ->callComposed4 : any ->composed4("test") : any ->composed4 : any +>callComposed4 : { boxed: string[]; } +>composed4("test") : { boxed: string[]; } +>composed4 : (a2: A) => { boxed: A[]; } >"test" : "test" const expectedCallComposed4 : {boxed: string[]} = callComposed4; >expectedCallComposed4 : { boxed: string[]; } >boxed : string[] ->callComposed4 : any +>callComposed4 : { boxed: string[]; } } { let composed5 = composeReverse( x2 => ({ boxed: x2 }), x => "" + x); ->composed5 : (d2: {}) => [{}, { boxed: string; }] ->composeReverse( x2 => ({ boxed: x2 }), x => "" + x) : (d2: {}) => [{}, { boxed: string; }] +>composed5 : (d2: D) => [D, { boxed: string; }] +>composeReverse( x2 => ({ boxed: x2 }), x => "" + x) : (d2: D) => [D, { boxed: string; }] >composeReverse : { (g: (e: E) => F, f: (d: D) => E): (d2: D) => [D, F]; (g: (b1: B) => C, f: (a1: A) => B): (a2: A) => C; } ->x2 => ({ boxed: x2 }) : (x2: string) => { boxed: string; } ->x2 : string ->({ boxed: x2 }) : { boxed: string; } ->{ boxed: x2 } : { boxed: string; } ->boxed : string ->x2 : string ->x => "" + x : (x: {}) => string ->x : {} +>x2 => ({ boxed: x2 }) : (x2: E) => { boxed: E; } +>x2 : E +>({ boxed: x2 }) : { boxed: E; } +>{ boxed: x2 } : { boxed: E; } +>boxed : E +>x2 : E +>x => "" + x : (x: D) => string +>x : D >"" + x : string >"" : "" ->x : {} +>x : D const expectedComposed5: (u: U) => [U, {boxed: string}] = composed5; >expectedComposed5 : (u: U) => [U, { boxed: string; }] @@ -442,17 +442,17 @@ declare function composeReverse(g: (b1: B) => C, f: (a1: A) => B): (a2: >U : U >U : U >boxed : string ->composed5 : (d2: {}) => [{}, { boxed: string; }] +>composed5 : (d2: D) => [D, { boxed: string; }] const callComposed5 = composed5(123456); ->callComposed5 : [{}, { boxed: string; }] ->composed5(123456) : [{}, { boxed: string; }] ->composed5 : (d2: {}) => [{}, { boxed: string; }] +>callComposed5 : [number, { boxed: string; }] +>composed5(123456) : [number, { boxed: string; }] +>composed5 : (d2: D) => [D, { boxed: string; }] >123456 : 123456 const expectedCallComposed5 : [number, {boxed: string}] = callComposed5; >expectedCallComposed5 : [number, { boxed: string; }] >boxed : string ->callComposed5 : [{}, { boxed: string; }] +>callComposed5 : [number, { boxed: string; }] } diff --git a/tests/baselines/reference/intersectionsOfLargeUnions.types b/tests/baselines/reference/intersectionsOfLargeUnions.types index 4deef4a4ecf88..a2763212bbda9 100644 --- a/tests/baselines/reference/intersectionsOfLargeUnions.types +++ b/tests/baselines/reference/intersectionsOfLargeUnions.types @@ -102,8 +102,8 @@ export function assertNodeProperty< >tagName : T node[prop]; ->node[prop] : ElementTagNameMap[T][P] ->node : ElementTagNameMap[T] +>node[prop] : U[P] +>node : U >prop : P } } diff --git a/tests/baselines/reference/jqueryInference.errors.txt b/tests/baselines/reference/jqueryInference.errors.txt new file mode 100644 index 0000000000000..bd15c5d5164a2 --- /dev/null +++ b/tests/baselines/reference/jqueryInference.errors.txt @@ -0,0 +1,20 @@ +tests/cases/compiler/jqueryInference.ts(13,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'p2' must be of type 'MyPromise', but here has type 'MyPromise'. + + +==== tests/cases/compiler/jqueryInference.ts (1 errors) ==== + // #22362 + interface MyPromise { + then(cb: (t: T) => void): void; + thenUnion(cb: (t: T | U) => void): this; + } + + interface DoNothingAlias extends MyPromise { } + + declare function shouldBeIdentity(p: DoNothingAlias): MyPromise; + + declare const p1: MyPromise; + var p2 = shouldBeIdentity(p1); + var p2: MyPromise; + ~~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'p2' must be of type 'MyPromise', but here has type 'MyPromise'. + \ No newline at end of file diff --git a/tests/baselines/reference/jqueryInference.types b/tests/baselines/reference/jqueryInference.types index e2a1ec5d81fa1..af4b0bfa6c3f5 100644 --- a/tests/baselines/reference/jqueryInference.types +++ b/tests/baselines/reference/jqueryInference.types @@ -44,12 +44,12 @@ declare const p1: MyPromise; >MyPromise : MyPromise var p2 = shouldBeIdentity(p1); ->p2 : MyPromise ->shouldBeIdentity(p1) : MyPromise +>p2 : MyPromise +>shouldBeIdentity(p1) : MyPromise >shouldBeIdentity : (p: DoNothingAlias) => MyPromise >p1 : MyPromise var p2: MyPromise; ->p2 : MyPromise +>p2 : MyPromise >MyPromise : MyPromise diff --git a/tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.errors.txt b/tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.errors.txt index 3c06fd4327536..eda45122a36eb 100644 --- a/tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.errors.txt +++ b/tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.errors.txt @@ -3,14 +3,10 @@ tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(14,37): Property 'x' is missing in type 'D'. tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(16,5): error TS2322: Type 'string' is not assignable to type 'number'. tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(16,38): error TS2344: Type 'D' does not satisfy the constraint 'A'. -tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(18,27): error TS2345: Argument of type '(x: D) => G' is not assignable to parameter of type '(x: B) => any'. - Types of parameters 'x' and 'x' are incompatible. - Type 'B' is not assignable to type 'D'. - Property 'q' is missing in type 'B'. tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(19,14): error TS2344: Type 'D' does not satisfy the constraint 'A'. -==== tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts (6 errors) ==== +==== tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts (5 errors) ==== interface A { x } interface B { x; y } interface C { z } @@ -38,11 +34,6 @@ tests/cases/compiler/overloadresolutionWithConstraintCheckingDeferred.ts(19,14): !!! error TS2344: Type 'D' does not satisfy the constraint 'A'. var result3: string = foo(x => { // x has type D - ~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2345: Argument of type '(x: D) => G' is not assignable to parameter of type '(x: B) => any'. -!!! error TS2345: Types of parameters 'x' and 'x' are incompatible. -!!! error TS2345: Type 'B' is not assignable to type 'D'. -!!! error TS2345: Property 'q' is missing in type 'B'. var y: G; // error that D does not satisfy constraint, y is of type G, entire call to foo is an error ~~~~~~~~ !!! error TS2344: Type 'D' does not satisfy the constraint 'A'. diff --git a/tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.types b/tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.types index 7005c6bc55478..db77b630988a3 100644 --- a/tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.types +++ b/tests/baselines/reference/overloadresolutionWithConstraintCheckingDeferred.types @@ -48,34 +48,34 @@ var result: number = foo(x => new G(x)); // x has type D, new G(x) fails, so fir >result : number >foo(x => new G(x)) : string >foo : { (arg: (x: D) => number): string; (arg: (x: C) => any): string; (arg: (x: B) => any): number; } ->x => new G(x) : (x: D) => any ->x : D +>x => new G(x) : (x: C) => any +>x : C >new G(x) : any >G : typeof G ->x : D +>x : C var result2: number = foo(x => new G(x)); // x has type D, new G(x) fails, so first overload is picked. >result2 : number >foo(x => new G(x)) : string >foo : { (arg: (x: D) => number): string; (arg: (x: C) => any): string; (arg: (x: B) => any): number; } ->x => new G(x) : (x: D) => any ->x : D +>x => new G(x) : (x: C) => any +>x : C >new G(x) : any >G : typeof G ->x : D ->x : D +>x : C +>x : C var result3: string = foo(x => { // x has type D >result3 : string ->foo(x => { // x has type D var y: G; // error that D does not satisfy constraint, y is of type G, entire call to foo is an error return y;}) : any +>foo(x => { // x has type D var y: G; // error that D does not satisfy constraint, y is of type G, entire call to foo is an error return y;}) : string >foo : { (arg: (x: D) => number): string; (arg: (x: C) => any): string; (arg: (x: B) => any): number; } ->x => { // x has type D var y: G; // error that D does not satisfy constraint, y is of type G, entire call to foo is an error return y;} : (x: D) => G ->x : D +>x => { // x has type D var y: G; // error that D does not satisfy constraint, y is of type G, entire call to foo is an error return y;} : (x: C) => G +>x : C var y: G; // error that D does not satisfy constraint, y is of type G, entire call to foo is an error >y : G >G : G ->x : D +>x : C return y; >y : G diff --git a/tests/baselines/reference/parenthesizedContexualTyping1.types b/tests/baselines/reference/parenthesizedContexualTyping1.types index d8272718cadca..9a09d16e8f4b6 100644 --- a/tests/baselines/reference/parenthesizedContexualTyping1.types +++ b/tests/baselines/reference/parenthesizedContexualTyping1.types @@ -187,8 +187,8 @@ var j = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), 10); >10 : 10 var k = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10); ->k : any ->fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10) : any +>k : number +>fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10) : number >fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } >(Math.random() < 0.5 ? (x => x) : (x => undefined)) : (x: number) => any >Math.random() < 0.5 ? (x => x) : (x => undefined) : (x: number) => any @@ -206,14 +206,14 @@ var k = fun((Math.random() < 0.5 ? (x => x) : (x => undefined)), x => x, 10); >x => undefined : (x: number) => any >x : number >undefined : undefined ->x => x : (x: any) => any ->x : any ->x : any +>x => x : (x: number) => number +>x : number +>x : number >10 : 10 var l = fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10); ->l : any ->fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10) : any +>l : number +>fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x)), 10) : number >fun : { (g: (x: T) => T, x: T): T; (g: (x: T) => T, h: (y: T) => T, x: T): T; } >((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))) : (x: number) => any >(Math.random() < 0.5 ? ((x => x)) : ((x => undefined))) : (x: number) => any @@ -234,11 +234,11 @@ var l = fun(((Math.random() < 0.5 ? ((x => x)) : ((x => undefined)))), ((x => x) >x => undefined : (x: number) => any >x : number >undefined : undefined ->((x => x)) : (x: any) => any ->(x => x) : (x: any) => any ->x => x : (x: any) => any ->x : any ->x : any +>((x => x)) : (x: number) => number +>(x => x) : (x: number) => number +>x => x : (x: number) => number +>x : number +>x : number >10 : 10 var lambda1: (x: number) => number = x => x; From ccb5dd4ab6abd3369b603c8d50aa24c2929c76ae Mon Sep 17 00:00:00 2001 From: Kevin Donnelly Date: Sat, 2 Jun 2018 15:15:57 -0500 Subject: [PATCH 4/4] Forgot that I had disabled building with local compiler. --- src/compiler/checker.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 0a67e586c9d48..139bcca89d1fb 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -19681,7 +19681,7 @@ namespace ts { const parameter = signature.parameters[i]; if (!getEffectiveTypeAnnotationNode(parameter.valueDeclaration)) { const contextualParameterType = getTypeAtPosition(context, i); - const originalContextualParameterType = signature.isContextuallyTyped ? getTypeAtPosition(context.target!, i) : undefined; + const originalContextualParameterType = signature.isContextuallyTyped && context.target ? getTypeAtPosition(context.target, i) : undefined; assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, contextualParameterType === originalContextualParameterType); for (const tp of getFreeTypeParameters(contextualParameterType)) { node.contextualTypeParameters = appendIfUnique(node.contextualTypeParameters, tp); @@ -19693,7 +19693,7 @@ namespace ts { const parameter = last(signature.parameters); if (isTransientSymbol(parameter) || !getEffectiveTypeAnnotationNode(parameter.valueDeclaration)) { const contextualParameterType = getTypeOfSymbol(last(context.parameters)); - const originalContextualParameterType = signature.isContextuallyTyped ? getTypeOfSymbol(last(context.target!.parameters)) : undefined; + const originalContextualParameterType = signature.isContextuallyTyped && context.target ? getTypeOfSymbol(last(context.target.parameters)) : undefined; assignTypeToParameterAndFixTypeParameters(parameter, contextualParameterType, contextualParameterType === originalContextualParameterType); for (const tp of getFreeTypeParameters(contextualParameterType)) { node.contextualTypeParameters = appendIfUnique(node.contextualTypeParameters, tp);