diff --git a/tests/baselines/reference/InferFromReturnsInContextSensitive1.js b/tests/baselines/reference/InferFromReturnsInContextSensitive1.js index f62ce1e4fdcbe..177dc45641039 100644 --- a/tests/baselines/reference/InferFromReturnsInContextSensitive1.js +++ b/tests/baselines/reference/InferFromReturnsInContextSensitive1.js @@ -17,6 +17,11 @@ create((arg) => ({ onEnd: (context) => {}, })); +create((arg) => ({ + onEnd: (context) => {}, + onStart: () => ({ time: new Date() }), +})); + // https://github.com/microsoft/TypeScript/issues/57021 type Schema = Record; @@ -26,13 +31,13 @@ type StepFunction = (anything: unknown) => { readonly toAnswers?: (keys: keyof TSchema) => unknown; }; -function step1( +function step( stepVal: StepFunction, ): StepFunction { return stepVal; } -const stepResult1 = step1((_something) => ({ +const stepResult1 = step((_something) => ({ schema: { attribute: "anything", }, @@ -42,6 +47,107 @@ const stepResult1 = step1((_something) => ({ return { test }; }, })); + +const stepResult2 = step((_something) => ({ + toAnswers: (keys) => { + type Test = string extends typeof keys ? never : "true"; + const test: Test = "true"; // ok + return { test }; + }, + schema: { + attribute: "anything", + }, +})); + +type Fn1 = (anything: unknown) => { + stuff: T; + consume: (arg: T) => (anything: unknown) => { + stuff2: T2; + consume2: (arg: T2) => void; + }; +}; + +declare function test1(fn: Fn1): [T, T2]; + +const res1 = test1((_something) => ({ + stuff: "foo", + consume: (arg) => { + return (_something) => ({ + stuff2: 42, + consume2: (arg2) => {}, + }); + }, +})); + +const res2 = test1((_something) => ({ + consume: (arg) => { + return (_something) => ({ + consume2: (arg2) => {}, + stuff2: 42, + }); + }, + stuff: "foo", +})); + +const res3 = test1((_something) => ({ + stuff: "foo", + consume: () => { + return (_something) => ({ + stuff2: 42, + consume2: (arg2) => {}, + }); + }, +})); + +const res4 = test1((_something) => ({ + consume: () => { + return (_something) => ({ + consume2: (arg2) => {}, + stuff2: 42, + }); + }, + stuff: "foo", +})); + +const res5 = test1((_something) => ({ + stuff: "foo", + consume: () => { + return () => ({ + stuff2: 42, + consume2: (arg2) => {}, + }); + }, +})); + +const res6 = test1((_something) => ({ + consume: () => { + return () => ({ + consume2: (arg2) => {}, + stuff2: 42, + }); + }, + stuff: "foo", +})); + +const res7 = test1((_something) => ({ + stuff: "foo", + consume: () => { + return () => ({ + stuff2: 42, + consume2: () => {}, + }); + }, +})); + +const res8 = test1((_something) => ({ + consume: () => { + return () => ({ + consume2: () => {}, + stuff2: 42, + }); + }, + stuff: "foo", +})); //// [InferFromReturnsInContextSensitive1.js] @@ -54,10 +160,14 @@ create(function (arg) { return ({ onStart: function () { return ({ time: new Date() }); }, onEnd: function (context) { }, }); }); -function step1(stepVal) { +create(function (arg) { return ({ + onEnd: function (context) { }, + onStart: function () { return ({ time: new Date() }); }, +}); }); +function step(stepVal) { return stepVal; } -var stepResult1 = step1(function (_something) { return ({ +var stepResult1 = step(function (_something) { return ({ schema: { attribute: "anything", }, @@ -66,6 +176,87 @@ var stepResult1 = step1(function (_something) { return ({ return { test: test }; }, }); }); +var stepResult2 = step(function (_something) { return ({ + toAnswers: function (keys) { + var test = "true"; // ok + return { test: test }; + }, + schema: { + attribute: "anything", + }, +}); }); +var res1 = test1(function (_something) { return ({ + stuff: "foo", + consume: function (arg) { + return function (_something) { return ({ + stuff2: 42, + consume2: function (arg2) { }, + }); }; + }, +}); }); +var res2 = test1(function (_something) { return ({ + consume: function (arg) { + return function (_something) { return ({ + consume2: function (arg2) { }, + stuff2: 42, + }); }; + }, + stuff: "foo", +}); }); +var res3 = test1(function (_something) { return ({ + stuff: "foo", + consume: function () { + return function (_something) { return ({ + stuff2: 42, + consume2: function (arg2) { }, + }); }; + }, +}); }); +var res4 = test1(function (_something) { return ({ + consume: function () { + return function (_something) { return ({ + consume2: function (arg2) { }, + stuff2: 42, + }); }; + }, + stuff: "foo", +}); }); +var res5 = test1(function (_something) { return ({ + stuff: "foo", + consume: function () { + return function () { return ({ + stuff2: 42, + consume2: function (arg2) { }, + }); }; + }, +}); }); +var res6 = test1(function (_something) { return ({ + consume: function () { + return function () { return ({ + consume2: function (arg2) { }, + stuff2: 42, + }); }; + }, + stuff: "foo", +}); }); +var res7 = test1(function (_something) { return ({ + stuff: "foo", + consume: function () { + return function () { return ({ + stuff2: 42, + consume2: function () { }, + }); }; + }, +}); }); +var res8 = test1(function (_something) { return ({ + consume: function () { + return function () { return ({ + consume2: function () { }, + stuff2: 42, + }); }; + }, + stuff: "foo", +}); }); //// [InferFromReturnsInContextSensitive1.d.ts] @@ -79,7 +270,26 @@ type StepFunction = (anything: unknown) => { readonly schema: TSchema; readonly toAnswers?: (keys: keyof TSchema) => unknown; }; -declare function step1(stepVal: StepFunction): StepFunction; +declare function step(stepVal: StepFunction): StepFunction; declare const stepResult1: StepFunction<{ attribute: string; }>; +declare const stepResult2: StepFunction<{ + attribute: string; +}>; +type Fn1 = (anything: unknown) => { + stuff: T; + consume: (arg: T) => (anything: unknown) => { + stuff2: T2; + consume2: (arg: T2) => void; + }; +}; +declare function test1(fn: Fn1): [T, T2]; +declare const res1: [string, number]; +declare const res2: [string, number]; +declare const res3: [string, number]; +declare const res4: [string, number]; +declare const res5: [string, number]; +declare const res6: [string, number]; +declare const res7: [string, number]; +declare const res8: [string, number]; diff --git a/tests/baselines/reference/InferFromReturnsInContextSensitive1.symbols b/tests/baselines/reference/InferFromReturnsInContextSensitive1.symbols index 0ed0951e1caf6..2b87289576f5b 100644 --- a/tests/baselines/reference/InferFromReturnsInContextSensitive1.symbols +++ b/tests/baselines/reference/InferFromReturnsInContextSensitive1.symbols @@ -45,76 +45,352 @@ create((arg) => ({ })); +create((arg) => ({ +>create : Symbol(create, Decl(InferFromReturnsInContextSensitive1.ts, 5, 2)) +>arg : Symbol(arg, Decl(InferFromReturnsInContextSensitive1.ts, 16, 8)) + + onEnd: (context) => {}, +>onEnd : Symbol(onEnd, Decl(InferFromReturnsInContextSensitive1.ts, 16, 18)) +>context : Symbol(context, Decl(InferFromReturnsInContextSensitive1.ts, 17, 10)) + + onStart: () => ({ time: new Date() }), +>onStart : Symbol(onStart, Decl(InferFromReturnsInContextSensitive1.ts, 17, 25)) +>time : Symbol(time, Decl(InferFromReturnsInContextSensitive1.ts, 18, 19)) +>Date : Symbol(Date, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.scripthost.d.ts, --, --)) + +})); + // https://github.com/microsoft/TypeScript/issues/57021 type Schema = Record; ->Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 14, 4)) +>Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 19, 4)) >Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) type StepFunction = (anything: unknown) => { ->StepFunction : Symbol(StepFunction, Decl(InferFromReturnsInContextSensitive1.ts, 18, 38)) ->TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 20, 18)) ->Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 14, 4)) ->Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 14, 4)) ->anything : Symbol(anything, Decl(InferFromReturnsInContextSensitive1.ts, 20, 54)) +>StepFunction : Symbol(StepFunction, Decl(InferFromReturnsInContextSensitive1.ts, 23, 38)) +>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 25, 18)) +>Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 19, 4)) +>Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 19, 4)) +>anything : Symbol(anything, Decl(InferFromReturnsInContextSensitive1.ts, 25, 54)) readonly schema: TSchema; ->schema : Symbol(schema, Decl(InferFromReturnsInContextSensitive1.ts, 20, 77)) ->TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 20, 18)) +>schema : Symbol(schema, Decl(InferFromReturnsInContextSensitive1.ts, 25, 77)) +>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 25, 18)) readonly toAnswers?: (keys: keyof TSchema) => unknown; ->toAnswers : Symbol(toAnswers, Decl(InferFromReturnsInContextSensitive1.ts, 21, 27)) ->keys : Symbol(keys, Decl(InferFromReturnsInContextSensitive1.ts, 22, 24)) ->TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 20, 18)) +>toAnswers : Symbol(toAnswers, Decl(InferFromReturnsInContextSensitive1.ts, 26, 27)) +>keys : Symbol(keys, Decl(InferFromReturnsInContextSensitive1.ts, 27, 24)) +>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 25, 18)) }; -function step1( ->step1 : Symbol(step1, Decl(InferFromReturnsInContextSensitive1.ts, 23, 2)) ->TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 25, 15)) ->Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 14, 4)) ->Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 14, 4)) +function step( +>step : Symbol(step, Decl(InferFromReturnsInContextSensitive1.ts, 28, 2)) +>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 30, 14)) +>Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 19, 4)) +>Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 19, 4)) stepVal: StepFunction, ->stepVal : Symbol(stepVal, Decl(InferFromReturnsInContextSensitive1.ts, 25, 48)) ->StepFunction : Symbol(StepFunction, Decl(InferFromReturnsInContextSensitive1.ts, 18, 38)) ->TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 25, 15)) +>stepVal : Symbol(stepVal, Decl(InferFromReturnsInContextSensitive1.ts, 30, 47)) +>StepFunction : Symbol(StepFunction, Decl(InferFromReturnsInContextSensitive1.ts, 23, 38)) +>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 30, 14)) ): StepFunction { ->StepFunction : Symbol(StepFunction, Decl(InferFromReturnsInContextSensitive1.ts, 18, 38)) ->TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 25, 15)) +>StepFunction : Symbol(StepFunction, Decl(InferFromReturnsInContextSensitive1.ts, 23, 38)) +>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 30, 14)) return stepVal; ->stepVal : Symbol(stepVal, Decl(InferFromReturnsInContextSensitive1.ts, 25, 48)) +>stepVal : Symbol(stepVal, Decl(InferFromReturnsInContextSensitive1.ts, 30, 47)) } -const stepResult1 = step1((_something) => ({ ->stepResult1 : Symbol(stepResult1, Decl(InferFromReturnsInContextSensitive1.ts, 31, 5)) ->step1 : Symbol(step1, Decl(InferFromReturnsInContextSensitive1.ts, 23, 2)) ->_something : Symbol(_something, Decl(InferFromReturnsInContextSensitive1.ts, 31, 27)) +const stepResult1 = step((_something) => ({ +>stepResult1 : Symbol(stepResult1, Decl(InferFromReturnsInContextSensitive1.ts, 36, 5)) +>step : Symbol(step, Decl(InferFromReturnsInContextSensitive1.ts, 28, 2)) +>_something : Symbol(_something, Decl(InferFromReturnsInContextSensitive1.ts, 36, 26)) schema: { ->schema : Symbol(schema, Decl(InferFromReturnsInContextSensitive1.ts, 31, 44)) +>schema : Symbol(schema, Decl(InferFromReturnsInContextSensitive1.ts, 36, 43)) attribute: "anything", ->attribute : Symbol(attribute, Decl(InferFromReturnsInContextSensitive1.ts, 32, 11)) +>attribute : Symbol(attribute, Decl(InferFromReturnsInContextSensitive1.ts, 37, 11)) + + }, + toAnswers: (keys) => { +>toAnswers : Symbol(toAnswers, Decl(InferFromReturnsInContextSensitive1.ts, 39, 4)) +>keys : Symbol(keys, Decl(InferFromReturnsInContextSensitive1.ts, 40, 14)) + + type Test = string extends typeof keys ? never : "true"; +>Test : Symbol(Test, Decl(InferFromReturnsInContextSensitive1.ts, 40, 24)) +>keys : Symbol(keys, Decl(InferFromReturnsInContextSensitive1.ts, 40, 14)) + + const test: Test = "true"; // ok +>test : Symbol(test, Decl(InferFromReturnsInContextSensitive1.ts, 42, 9)) +>Test : Symbol(Test, Decl(InferFromReturnsInContextSensitive1.ts, 40, 24)) + + return { test }; +>test : Symbol(test, Decl(InferFromReturnsInContextSensitive1.ts, 43, 12)) }, +})); + +const stepResult2 = step((_something) => ({ +>stepResult2 : Symbol(stepResult2, Decl(InferFromReturnsInContextSensitive1.ts, 47, 5)) +>step : Symbol(step, Decl(InferFromReturnsInContextSensitive1.ts, 28, 2)) +>_something : Symbol(_something, Decl(InferFromReturnsInContextSensitive1.ts, 47, 26)) + toAnswers: (keys) => { ->toAnswers : Symbol(toAnswers, Decl(InferFromReturnsInContextSensitive1.ts, 34, 4)) ->keys : Symbol(keys, Decl(InferFromReturnsInContextSensitive1.ts, 35, 14)) +>toAnswers : Symbol(toAnswers, Decl(InferFromReturnsInContextSensitive1.ts, 47, 43)) +>keys : Symbol(keys, Decl(InferFromReturnsInContextSensitive1.ts, 48, 14)) type Test = string extends typeof keys ? never : "true"; ->Test : Symbol(Test, Decl(InferFromReturnsInContextSensitive1.ts, 35, 24)) ->keys : Symbol(keys, Decl(InferFromReturnsInContextSensitive1.ts, 35, 14)) +>Test : Symbol(Test, Decl(InferFromReturnsInContextSensitive1.ts, 48, 24)) +>keys : Symbol(keys, Decl(InferFromReturnsInContextSensitive1.ts, 48, 14)) const test: Test = "true"; // ok ->test : Symbol(test, Decl(InferFromReturnsInContextSensitive1.ts, 37, 9)) ->Test : Symbol(Test, Decl(InferFromReturnsInContextSensitive1.ts, 35, 24)) +>test : Symbol(test, Decl(InferFromReturnsInContextSensitive1.ts, 50, 9)) +>Test : Symbol(Test, Decl(InferFromReturnsInContextSensitive1.ts, 48, 24)) return { test }; ->test : Symbol(test, Decl(InferFromReturnsInContextSensitive1.ts, 38, 12)) +>test : Symbol(test, Decl(InferFromReturnsInContextSensitive1.ts, 51, 12)) + + }, + schema: { +>schema : Symbol(schema, Decl(InferFromReturnsInContextSensitive1.ts, 52, 4)) + + attribute: "anything", +>attribute : Symbol(attribute, Decl(InferFromReturnsInContextSensitive1.ts, 53, 11)) + + }, +})); + +type Fn1 = (anything: unknown) => { +>Fn1 : Symbol(Fn1, Decl(InferFromReturnsInContextSensitive1.ts, 56, 4)) +>T : Symbol(T, Decl(InferFromReturnsInContextSensitive1.ts, 58, 9)) +>T2 : Symbol(T2, Decl(InferFromReturnsInContextSensitive1.ts, 58, 11)) +>anything : Symbol(anything, Decl(InferFromReturnsInContextSensitive1.ts, 58, 19)) + + stuff: T; +>stuff : Symbol(stuff, Decl(InferFromReturnsInContextSensitive1.ts, 58, 42)) +>T : Symbol(T, Decl(InferFromReturnsInContextSensitive1.ts, 58, 9)) + + consume: (arg: T) => (anything: unknown) => { +>consume : Symbol(consume, Decl(InferFromReturnsInContextSensitive1.ts, 59, 11)) +>arg : Symbol(arg, Decl(InferFromReturnsInContextSensitive1.ts, 60, 12)) +>T : Symbol(T, Decl(InferFromReturnsInContextSensitive1.ts, 58, 9)) +>anything : Symbol(anything, Decl(InferFromReturnsInContextSensitive1.ts, 60, 24)) + + stuff2: T2; +>stuff2 : Symbol(stuff2, Decl(InferFromReturnsInContextSensitive1.ts, 60, 47)) +>T2 : Symbol(T2, Decl(InferFromReturnsInContextSensitive1.ts, 58, 11)) + + consume2: (arg: T2) => void; +>consume2 : Symbol(consume2, Decl(InferFromReturnsInContextSensitive1.ts, 61, 15)) +>arg : Symbol(arg, Decl(InferFromReturnsInContextSensitive1.ts, 62, 15)) +>T2 : Symbol(T2, Decl(InferFromReturnsInContextSensitive1.ts, 58, 11)) + + }; +}; + +declare function test1(fn: Fn1): [T, T2]; +>test1 : Symbol(test1, Decl(InferFromReturnsInContextSensitive1.ts, 64, 2)) +>T : Symbol(T, Decl(InferFromReturnsInContextSensitive1.ts, 66, 23)) +>T2 : Symbol(T2, Decl(InferFromReturnsInContextSensitive1.ts, 66, 25)) +>fn : Symbol(fn, Decl(InferFromReturnsInContextSensitive1.ts, 66, 30)) +>Fn1 : Symbol(Fn1, Decl(InferFromReturnsInContextSensitive1.ts, 56, 4)) +>T : Symbol(T, Decl(InferFromReturnsInContextSensitive1.ts, 66, 23)) +>T2 : Symbol(T2, Decl(InferFromReturnsInContextSensitive1.ts, 66, 25)) +>T : Symbol(T, Decl(InferFromReturnsInContextSensitive1.ts, 66, 23)) +>T2 : Symbol(T2, Decl(InferFromReturnsInContextSensitive1.ts, 66, 25)) + +const res1 = test1((_something) => ({ +>res1 : Symbol(res1, Decl(InferFromReturnsInContextSensitive1.ts, 68, 5)) +>test1 : Symbol(test1, Decl(InferFromReturnsInContextSensitive1.ts, 64, 2)) +>_something : Symbol(_something, Decl(InferFromReturnsInContextSensitive1.ts, 68, 20)) + + stuff: "foo", +>stuff : Symbol(stuff, Decl(InferFromReturnsInContextSensitive1.ts, 68, 37)) + + consume: (arg) => { +>consume : Symbol(consume, Decl(InferFromReturnsInContextSensitive1.ts, 69, 15)) +>arg : Symbol(arg, Decl(InferFromReturnsInContextSensitive1.ts, 70, 12)) + + return (_something) => ({ +>_something : Symbol(_something, Decl(InferFromReturnsInContextSensitive1.ts, 71, 12)) + + stuff2: 42, +>stuff2 : Symbol(stuff2, Decl(InferFromReturnsInContextSensitive1.ts, 71, 29)) + + consume2: (arg2) => {}, +>consume2 : Symbol(consume2, Decl(InferFromReturnsInContextSensitive1.ts, 72, 17)) +>arg2 : Symbol(arg2, Decl(InferFromReturnsInContextSensitive1.ts, 73, 17)) + + }); + }, +})); + +const res2 = test1((_something) => ({ +>res2 : Symbol(res2, Decl(InferFromReturnsInContextSensitive1.ts, 78, 5)) +>test1 : Symbol(test1, Decl(InferFromReturnsInContextSensitive1.ts, 64, 2)) +>_something : Symbol(_something, Decl(InferFromReturnsInContextSensitive1.ts, 78, 20)) + + consume: (arg) => { +>consume : Symbol(consume, Decl(InferFromReturnsInContextSensitive1.ts, 78, 37)) +>arg : Symbol(arg, Decl(InferFromReturnsInContextSensitive1.ts, 79, 12)) + + return (_something) => ({ +>_something : Symbol(_something, Decl(InferFromReturnsInContextSensitive1.ts, 80, 12)) + + consume2: (arg2) => {}, +>consume2 : Symbol(consume2, Decl(InferFromReturnsInContextSensitive1.ts, 80, 29)) +>arg2 : Symbol(arg2, Decl(InferFromReturnsInContextSensitive1.ts, 81, 17)) + + stuff2: 42, +>stuff2 : Symbol(stuff2, Decl(InferFromReturnsInContextSensitive1.ts, 81, 29)) + }); }, + stuff: "foo", +>stuff : Symbol(stuff, Decl(InferFromReturnsInContextSensitive1.ts, 84, 4)) + +})); + +const res3 = test1((_something) => ({ +>res3 : Symbol(res3, Decl(InferFromReturnsInContextSensitive1.ts, 88, 5)) +>test1 : Symbol(test1, Decl(InferFromReturnsInContextSensitive1.ts, 64, 2)) +>_something : Symbol(_something, Decl(InferFromReturnsInContextSensitive1.ts, 88, 20)) + + stuff: "foo", +>stuff : Symbol(stuff, Decl(InferFromReturnsInContextSensitive1.ts, 88, 37)) + + consume: () => { +>consume : Symbol(consume, Decl(InferFromReturnsInContextSensitive1.ts, 89, 15)) + + return (_something) => ({ +>_something : Symbol(_something, Decl(InferFromReturnsInContextSensitive1.ts, 91, 12)) + + stuff2: 42, +>stuff2 : Symbol(stuff2, Decl(InferFromReturnsInContextSensitive1.ts, 91, 29)) + + consume2: (arg2) => {}, +>consume2 : Symbol(consume2, Decl(InferFromReturnsInContextSensitive1.ts, 92, 17)) +>arg2 : Symbol(arg2, Decl(InferFromReturnsInContextSensitive1.ts, 93, 17)) + + }); + }, +})); + +const res4 = test1((_something) => ({ +>res4 : Symbol(res4, Decl(InferFromReturnsInContextSensitive1.ts, 98, 5)) +>test1 : Symbol(test1, Decl(InferFromReturnsInContextSensitive1.ts, 64, 2)) +>_something : Symbol(_something, Decl(InferFromReturnsInContextSensitive1.ts, 98, 20)) + + consume: () => { +>consume : Symbol(consume, Decl(InferFromReturnsInContextSensitive1.ts, 98, 37)) + + return (_something) => ({ +>_something : Symbol(_something, Decl(InferFromReturnsInContextSensitive1.ts, 100, 12)) + + consume2: (arg2) => {}, +>consume2 : Symbol(consume2, Decl(InferFromReturnsInContextSensitive1.ts, 100, 29)) +>arg2 : Symbol(arg2, Decl(InferFromReturnsInContextSensitive1.ts, 101, 17)) + + stuff2: 42, +>stuff2 : Symbol(stuff2, Decl(InferFromReturnsInContextSensitive1.ts, 101, 29)) + + }); + }, + stuff: "foo", +>stuff : Symbol(stuff, Decl(InferFromReturnsInContextSensitive1.ts, 104, 4)) + +})); + +const res5 = test1((_something) => ({ +>res5 : Symbol(res5, Decl(InferFromReturnsInContextSensitive1.ts, 108, 5)) +>test1 : Symbol(test1, Decl(InferFromReturnsInContextSensitive1.ts, 64, 2)) +>_something : Symbol(_something, Decl(InferFromReturnsInContextSensitive1.ts, 108, 20)) + + stuff: "foo", +>stuff : Symbol(stuff, Decl(InferFromReturnsInContextSensitive1.ts, 108, 37)) + + consume: () => { +>consume : Symbol(consume, Decl(InferFromReturnsInContextSensitive1.ts, 109, 15)) + + return () => ({ + stuff2: 42, +>stuff2 : Symbol(stuff2, Decl(InferFromReturnsInContextSensitive1.ts, 111, 19)) + + consume2: (arg2) => {}, +>consume2 : Symbol(consume2, Decl(InferFromReturnsInContextSensitive1.ts, 112, 17)) +>arg2 : Symbol(arg2, Decl(InferFromReturnsInContextSensitive1.ts, 113, 17)) + + }); + }, +})); + +const res6 = test1((_something) => ({ +>res6 : Symbol(res6, Decl(InferFromReturnsInContextSensitive1.ts, 118, 5)) +>test1 : Symbol(test1, Decl(InferFromReturnsInContextSensitive1.ts, 64, 2)) +>_something : Symbol(_something, Decl(InferFromReturnsInContextSensitive1.ts, 118, 20)) + + consume: () => { +>consume : Symbol(consume, Decl(InferFromReturnsInContextSensitive1.ts, 118, 37)) + + return () => ({ + consume2: (arg2) => {}, +>consume2 : Symbol(consume2, Decl(InferFromReturnsInContextSensitive1.ts, 120, 19)) +>arg2 : Symbol(arg2, Decl(InferFromReturnsInContextSensitive1.ts, 121, 17)) + + stuff2: 42, +>stuff2 : Symbol(stuff2, Decl(InferFromReturnsInContextSensitive1.ts, 121, 29)) + + }); + }, + stuff: "foo", +>stuff : Symbol(stuff, Decl(InferFromReturnsInContextSensitive1.ts, 124, 4)) + +})); + +const res7 = test1((_something) => ({ +>res7 : Symbol(res7, Decl(InferFromReturnsInContextSensitive1.ts, 128, 5)) +>test1 : Symbol(test1, Decl(InferFromReturnsInContextSensitive1.ts, 64, 2)) +>_something : Symbol(_something, Decl(InferFromReturnsInContextSensitive1.ts, 128, 20)) + + stuff: "foo", +>stuff : Symbol(stuff, Decl(InferFromReturnsInContextSensitive1.ts, 128, 37)) + + consume: () => { +>consume : Symbol(consume, Decl(InferFromReturnsInContextSensitive1.ts, 129, 15)) + + return () => ({ + stuff2: 42, +>stuff2 : Symbol(stuff2, Decl(InferFromReturnsInContextSensitive1.ts, 131, 19)) + + consume2: () => {}, +>consume2 : Symbol(consume2, Decl(InferFromReturnsInContextSensitive1.ts, 132, 17)) + + }); + }, +})); + +const res8 = test1((_something) => ({ +>res8 : Symbol(res8, Decl(InferFromReturnsInContextSensitive1.ts, 138, 5)) +>test1 : Symbol(test1, Decl(InferFromReturnsInContextSensitive1.ts, 64, 2)) +>_something : Symbol(_something, Decl(InferFromReturnsInContextSensitive1.ts, 138, 20)) + + consume: () => { +>consume : Symbol(consume, Decl(InferFromReturnsInContextSensitive1.ts, 138, 37)) + + return () => ({ + consume2: () => {}, +>consume2 : Symbol(consume2, Decl(InferFromReturnsInContextSensitive1.ts, 140, 19)) + + stuff2: 42, +>stuff2 : Symbol(stuff2, Decl(InferFromReturnsInContextSensitive1.ts, 141, 25)) + + }); + }, + stuff: "foo", +>stuff : Symbol(stuff, Decl(InferFromReturnsInContextSensitive1.ts, 144, 4)) + })); diff --git a/tests/baselines/reference/InferFromReturnsInContextSensitive1.types b/tests/baselines/reference/InferFromReturnsInContextSensitive1.types index 93de793ca595f..c3fe947d1e083 100644 --- a/tests/baselines/reference/InferFromReturnsInContextSensitive1.types +++ b/tests/baselines/reference/InferFromReturnsInContextSensitive1.types @@ -76,6 +76,46 @@ create((arg) => ({ })); +create((arg) => ({ +>create((arg) => ({ onEnd: (context) => {}, onStart: () => ({ time: new Date() }),})) : Options<{ time: Date; }> +> : ^^^^^^^^^^^^^^^^^^^^^^^^ +>create : (builder: (arg: boolean) => Options) => Options +> : ^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^ +>(arg) => ({ onEnd: (context) => {}, onStart: () => ({ time: new Date() }),}) : (arg: boolean) => { onEnd: (context: { time: Date; }) => void; onStart: () => { time: Date; }; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>arg : boolean +> : ^^^^^^^ +>({ onEnd: (context) => {}, onStart: () => ({ time: new Date() }),}) : { onEnd: (context: { time: Date; }) => void; onStart: () => { time: Date; }; } +> : ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ onEnd: (context) => {}, onStart: () => ({ time: new Date() }),} : { onEnd: (context: { time: Date; }) => void; onStart: () => { time: Date; }; } +> : ^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + onEnd: (context) => {}, +>onEnd : (context: { time: Date; }) => void +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ +>(context) => {} : (context: { time: Date; }) => void +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ +>context : { time: Date; } +> : ^^^^^^^^^^^^^^^ + + onStart: () => ({ time: new Date() }), +>onStart : () => { time: Date; } +> : ^^^^^^^^^^^^^^^^^^^^^ +>() => ({ time: new Date() }) : () => { time: Date; } +> : ^^^^^^^^^^^^^^^^^^^^^ +>({ time: new Date() }) : { time: Date; } +> : ^^^^^^^^^^^^^^^ +>{ time: new Date() } : { time: Date; } +> : ^^^^^^^^^^^^^^^ +>time : Date +> : ^^^^ +>new Date() : Date +> : ^^^^ +>Date : DateConstructor +> : ^^^^^^^^^^^^^^^ + +})); + // https://github.com/microsoft/TypeScript/issues/57021 type Schema = Record; @@ -100,9 +140,9 @@ type StepFunction = (anything: unknown) => { }; -function step1( ->step1 : (stepVal: StepFunction) => StepFunction -> : ^ ^^^^^^^^^ ^^^^^^^^^^^ ^^ ^^^^^ +function step( +>step : (stepVal: StepFunction) => StepFunction +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ ^^ ^^^^^ stepVal: StepFunction, >stepVal : StepFunction @@ -114,13 +154,13 @@ function step1( > : ^^^^^^^^^^^^^^^^^^^^^ } -const stepResult1 = step1((_something) => ({ +const stepResult1 = step((_something) => ({ >stepResult1 : StepFunction<{ attribute: string; }> > : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->step1((_something) => ({ schema: { attribute: "anything", }, toAnswers: (keys) => { type Test = string extends typeof keys ? never : "true"; const test: Test = "true"; // ok return { test }; },})) : StepFunction<{ attribute: string; }> -> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ->step1 : (stepVal: StepFunction) => StepFunction -> : ^ ^^^^^^^^^ ^^^^^^^^^^^ ^^ ^^^^^ +>step((_something) => ({ schema: { attribute: "anything", }, toAnswers: (keys) => { type Test = string extends typeof keys ? never : "true"; const test: Test = "true"; // ok return { test }; },})) : StepFunction<{ attribute: string; }> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>step : (stepVal: StepFunction) => StepFunction +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ ^^ ^^^^^ >(_something) => ({ schema: { attribute: "anything", }, toAnswers: (keys) => { type Test = string extends typeof keys ? never : "true"; const test: Test = "true"; // ok return { test }; },}) : (_something: unknown) => { schema: { attribute: string; }; toAnswers: (keys: "attribute") => { test: "true"; }; } > : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >_something : unknown @@ -172,3 +212,538 @@ const stepResult1 = step1((_something) => ({ }, })); +const stepResult2 = step((_something) => ({ +>stepResult2 : StepFunction<{ attribute: string; }> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>step((_something) => ({ toAnswers: (keys) => { type Test = string extends typeof keys ? never : "true"; const test: Test = "true"; // ok return { test }; }, schema: { attribute: "anything", },})) : StepFunction<{ attribute: string; }> +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>step : (stepVal: StepFunction) => StepFunction +> : ^ ^^^^^^^^^ ^^^^^^^^^^^ ^^ ^^^^^ +>(_something) => ({ toAnswers: (keys) => { type Test = string extends typeof keys ? never : "true"; const test: Test = "true"; // ok return { test }; }, schema: { attribute: "anything", },}) : (_something: unknown) => { toAnswers: (keys: "attribute") => { test: "true"; }; schema: { attribute: string; }; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>_something : unknown +> : ^^^^^^^ +>({ toAnswers: (keys) => { type Test = string extends typeof keys ? never : "true"; const test: Test = "true"; // ok return { test }; }, schema: { attribute: "anything", },}) : { toAnswers: (keys: "attribute") => { test: "true"; }; schema: { attribute: string; }; } +> : ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ toAnswers: (keys) => { type Test = string extends typeof keys ? never : "true"; const test: Test = "true"; // ok return { test }; }, schema: { attribute: "anything", },} : { toAnswers: (keys: "attribute") => { test: "true"; }; schema: { attribute: string; }; } +> : ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + toAnswers: (keys) => { +>toAnswers : (keys: "attribute") => { test: "true"; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>(keys) => { type Test = string extends typeof keys ? never : "true"; const test: Test = "true"; // ok return { test }; } : (keys: "attribute") => { test: "true"; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>keys : "attribute" +> : ^^^^^^^^^^^ + + type Test = string extends typeof keys ? never : "true"; +>Test : "true" +> : ^^^^^^ +>keys : "attribute" +> : ^^^^^^^^^^^ + + const test: Test = "true"; // ok +>test : "true" +> : ^^^^^^ +>"true" : "true" +> : ^^^^^^ + + return { test }; +>{ test } : { test: "true"; } +> : ^^^^^^^^^^^^^^^^^ +>test : "true" +> : ^^^^^^ + + }, + schema: { +>schema : { attribute: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^ +>{ attribute: "anything", } : { attribute: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^ + + attribute: "anything", +>attribute : string +> : ^^^^^^ +>"anything" : "anything" +> : ^^^^^^^^^^ + + }, +})); + +type Fn1 = (anything: unknown) => { +>Fn1 : Fn1 +> : ^^^^^^^^^^ +>anything : unknown +> : ^^^^^^^ + + stuff: T; +>stuff : T +> : ^ + + consume: (arg: T) => (anything: unknown) => { +>consume : (arg: T) => (anything: unknown) => { stuff2: T2; consume2: (arg: T2) => void; } +> : ^ ^^ ^^^^^ +>arg : T +> : ^ +>anything : unknown +> : ^^^^^^^ + + stuff2: T2; +>stuff2 : T2 +> : ^^ + + consume2: (arg: T2) => void; +>consume2 : (arg: T2) => void +> : ^ ^^ ^^^^^ +>arg : T2 +> : ^^ + + }; +}; + +declare function test1(fn: Fn1): [T, T2]; +>test1 : (fn: Fn1) => [T, T2] +> : ^ ^^ ^^ ^^ ^^^^^ +>fn : Fn1 +> : ^^^^^^^^^^ + +const res1 = test1((_something) => ({ +>res1 : [string, number] +> : ^^^^^^^^^^^^^^^^ +>test1((_something) => ({ stuff: "foo", consume: (arg) => { return (_something) => ({ stuff2: 42, consume2: (arg2) => {}, }); },})) : [string, number] +> : ^^^^^^^^^^^^^^^^ +>test1 : (fn: Fn1) => [T, T2] +> : ^ ^^ ^^ ^^ ^^^^^ +>(_something) => ({ stuff: "foo", consume: (arg) => { return (_something) => ({ stuff2: 42, consume2: (arg2) => {}, }); },}) : (_something: unknown) => { stuff: string; consume: (arg: string) => (_something: unknown) => { stuff2: number; consume2: (arg2: number) => void; }; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ +>_something : unknown +> : ^^^^^^^ +>({ stuff: "foo", consume: (arg) => { return (_something) => ({ stuff2: 42, consume2: (arg2) => {}, }); },}) : { stuff: string; consume: (arg: string) => (_something: unknown) => { stuff2: number; consume2: (arg2: number) => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ +>{ stuff: "foo", consume: (arg) => { return (_something) => ({ stuff2: 42, consume2: (arg2) => {}, }); },} : { stuff: string; consume: (arg: string) => (_something: unknown) => { stuff2: number; consume2: (arg2: number) => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ + + stuff: "foo", +>stuff : string +> : ^^^^^^ +>"foo" : "foo" +> : ^^^^^ + + consume: (arg) => { +>consume : (arg: string) => (_something: unknown) => { stuff2: number; consume2: (arg2: number) => void; } +> : ^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ +>(arg) => { return (_something) => ({ stuff2: 42, consume2: (arg2) => {}, }); } : (arg: string) => (_something: unknown) => { stuff2: number; consume2: (arg2: number) => void; } +> : ^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ +>arg : string +> : ^^^^^^ + + return (_something) => ({ +>(_something) => ({ stuff2: 42, consume2: (arg2) => {}, }) : (_something: unknown) => { stuff2: number; consume2: (arg2: number) => void; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ +>_something : unknown +> : ^^^^^^^ +>({ stuff2: 42, consume2: (arg2) => {}, }) : { stuff2: number; consume2: (arg2: number) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ +>{ stuff2: 42, consume2: (arg2) => {}, } : { stuff2: number; consume2: (arg2: number) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ + + stuff2: 42, +>stuff2 : number +> : ^^^^^^ +>42 : 42 +> : ^^ + + consume2: (arg2) => {}, +>consume2 : (arg2: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>(arg2) => {} : (arg2: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>arg2 : number +> : ^^^^^^ + + }); + }, +})); + +const res2 = test1((_something) => ({ +>res2 : [string, number] +> : ^^^^^^^^^^^^^^^^ +>test1((_something) => ({ consume: (arg) => { return (_something) => ({ consume2: (arg2) => {}, stuff2: 42, }); }, stuff: "foo",})) : [string, number] +> : ^^^^^^^^^^^^^^^^ +>test1 : (fn: Fn1) => [T, T2] +> : ^ ^^ ^^ ^^ ^^^^^ +>(_something) => ({ consume: (arg) => { return (_something) => ({ consume2: (arg2) => {}, stuff2: 42, }); }, stuff: "foo",}) : (_something: unknown) => { consume: (arg: string) => (_something: unknown) => { consume2: (arg2: number) => void; stuff2: number; }; stuff: string; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>_something : unknown +> : ^^^^^^^ +>({ consume: (arg) => { return (_something) => ({ consume2: (arg2) => {}, stuff2: 42, }); }, stuff: "foo",}) : { consume: (arg: string) => (_something: unknown) => { consume2: (arg2: number) => void; stuff2: number; }; stuff: string; } +> : ^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ consume: (arg) => { return (_something) => ({ consume2: (arg2) => {}, stuff2: 42, }); }, stuff: "foo",} : { consume: (arg: string) => (_something: unknown) => { consume2: (arg2: number) => void; stuff2: number; }; stuff: string; } +> : ^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + consume: (arg) => { +>consume : (arg: string) => (_something: unknown) => { consume2: (arg2: number) => void; stuff2: number; } +> : ^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>(arg) => { return (_something) => ({ consume2: (arg2) => {}, stuff2: 42, }); } : (arg: string) => (_something: unknown) => { consume2: (arg2: number) => void; stuff2: number; } +> : ^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>arg : string +> : ^^^^^^ + + return (_something) => ({ +>(_something) => ({ consume2: (arg2) => {}, stuff2: 42, }) : (_something: unknown) => { consume2: (arg2: number) => void; stuff2: number; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>_something : unknown +> : ^^^^^^^ +>({ consume2: (arg2) => {}, stuff2: 42, }) : { consume2: (arg2: number) => void; stuff2: number; } +> : ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ consume2: (arg2) => {}, stuff2: 42, } : { consume2: (arg2: number) => void; stuff2: number; } +> : ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + consume2: (arg2) => {}, +>consume2 : (arg2: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>(arg2) => {} : (arg2: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>arg2 : number +> : ^^^^^^ + + stuff2: 42, +>stuff2 : number +> : ^^^^^^ +>42 : 42 +> : ^^ + + }); + }, + stuff: "foo", +>stuff : string +> : ^^^^^^ +>"foo" : "foo" +> : ^^^^^ + +})); + +const res3 = test1((_something) => ({ +>res3 : [string, number] +> : ^^^^^^^^^^^^^^^^ +>test1((_something) => ({ stuff: "foo", consume: () => { return (_something) => ({ stuff2: 42, consume2: (arg2) => {}, }); },})) : [string, number] +> : ^^^^^^^^^^^^^^^^ +>test1 : (fn: Fn1) => [T, T2] +> : ^ ^^ ^^ ^^ ^^^^^ +>(_something) => ({ stuff: "foo", consume: () => { return (_something) => ({ stuff2: 42, consume2: (arg2) => {}, }); },}) : (_something: unknown) => { stuff: string; consume: () => (_something: unknown) => { stuff2: number; consume2: (arg2: number) => void; }; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ +>_something : unknown +> : ^^^^^^^ +>({ stuff: "foo", consume: () => { return (_something) => ({ stuff2: 42, consume2: (arg2) => {}, }); },}) : { stuff: string; consume: () => (_something: unknown) => { stuff2: number; consume2: (arg2: number) => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ +>{ stuff: "foo", consume: () => { return (_something) => ({ stuff2: 42, consume2: (arg2) => {}, }); },} : { stuff: string; consume: () => (_something: unknown) => { stuff2: number; consume2: (arg2: number) => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ + + stuff: "foo", +>stuff : string +> : ^^^^^^ +>"foo" : "foo" +> : ^^^^^ + + consume: () => { +>consume : () => (_something: unknown) => { stuff2: number; consume2: (arg2: number) => void; } +> : ^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ +>() => { return (_something) => ({ stuff2: 42, consume2: (arg2) => {}, }); } : () => (_something: unknown) => { stuff2: number; consume2: (arg2: number) => void; } +> : ^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ + + return (_something) => ({ +>(_something) => ({ stuff2: 42, consume2: (arg2) => {}, }) : (_something: unknown) => { stuff2: number; consume2: (arg2: number) => void; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ +>_something : unknown +> : ^^^^^^^ +>({ stuff2: 42, consume2: (arg2) => {}, }) : { stuff2: number; consume2: (arg2: number) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ +>{ stuff2: 42, consume2: (arg2) => {}, } : { stuff2: number; consume2: (arg2: number) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ + + stuff2: 42, +>stuff2 : number +> : ^^^^^^ +>42 : 42 +> : ^^ + + consume2: (arg2) => {}, +>consume2 : (arg2: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>(arg2) => {} : (arg2: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>arg2 : number +> : ^^^^^^ + + }); + }, +})); + +const res4 = test1((_something) => ({ +>res4 : [string, number] +> : ^^^^^^^^^^^^^^^^ +>test1((_something) => ({ consume: () => { return (_something) => ({ consume2: (arg2) => {}, stuff2: 42, }); }, stuff: "foo",})) : [string, number] +> : ^^^^^^^^^^^^^^^^ +>test1 : (fn: Fn1) => [T, T2] +> : ^ ^^ ^^ ^^ ^^^^^ +>(_something) => ({ consume: () => { return (_something) => ({ consume2: (arg2) => {}, stuff2: 42, }); }, stuff: "foo",}) : (_something: unknown) => { consume: () => (_something: unknown) => { consume2: (arg2: number) => void; stuff2: number; }; stuff: string; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>_something : unknown +> : ^^^^^^^ +>({ consume: () => { return (_something) => ({ consume2: (arg2) => {}, stuff2: 42, }); }, stuff: "foo",}) : { consume: () => (_something: unknown) => { consume2: (arg2: number) => void; stuff2: number; }; stuff: string; } +> : ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ consume: () => { return (_something) => ({ consume2: (arg2) => {}, stuff2: 42, }); }, stuff: "foo",} : { consume: () => (_something: unknown) => { consume2: (arg2: number) => void; stuff2: number; }; stuff: string; } +> : ^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + consume: () => { +>consume : () => (_something: unknown) => { consume2: (arg2: number) => void; stuff2: number; } +> : ^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>() => { return (_something) => ({ consume2: (arg2) => {}, stuff2: 42, }); } : () => (_something: unknown) => { consume2: (arg2: number) => void; stuff2: number; } +> : ^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + return (_something) => ({ +>(_something) => ({ consume2: (arg2) => {}, stuff2: 42, }) : (_something: unknown) => { consume2: (arg2: number) => void; stuff2: number; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>_something : unknown +> : ^^^^^^^ +>({ consume2: (arg2) => {}, stuff2: 42, }) : { consume2: (arg2: number) => void; stuff2: number; } +> : ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ consume2: (arg2) => {}, stuff2: 42, } : { consume2: (arg2: number) => void; stuff2: number; } +> : ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + consume2: (arg2) => {}, +>consume2 : (arg2: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>(arg2) => {} : (arg2: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>arg2 : number +> : ^^^^^^ + + stuff2: 42, +>stuff2 : number +> : ^^^^^^ +>42 : 42 +> : ^^ + + }); + }, + stuff: "foo", +>stuff : string +> : ^^^^^^ +>"foo" : "foo" +> : ^^^^^ + +})); + +const res5 = test1((_something) => ({ +>res5 : [string, number] +> : ^^^^^^^^^^^^^^^^ +>test1((_something) => ({ stuff: "foo", consume: () => { return () => ({ stuff2: 42, consume2: (arg2) => {}, }); },})) : [string, number] +> : ^^^^^^^^^^^^^^^^ +>test1 : (fn: Fn1) => [T, T2] +> : ^ ^^ ^^ ^^ ^^^^^ +>(_something) => ({ stuff: "foo", consume: () => { return () => ({ stuff2: 42, consume2: (arg2) => {}, }); },}) : (_something: unknown) => { stuff: string; consume: () => () => { stuff2: number; consume2: (arg2: number) => void; }; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ +>_something : unknown +> : ^^^^^^^ +>({ stuff: "foo", consume: () => { return () => ({ stuff2: 42, consume2: (arg2) => {}, }); },}) : { stuff: string; consume: () => () => { stuff2: number; consume2: (arg2: number) => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ +>{ stuff: "foo", consume: () => { return () => ({ stuff2: 42, consume2: (arg2) => {}, }); },} : { stuff: string; consume: () => () => { stuff2: number; consume2: (arg2: number) => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ + + stuff: "foo", +>stuff : string +> : ^^^^^^ +>"foo" : "foo" +> : ^^^^^ + + consume: () => { +>consume : () => () => { stuff2: number; consume2: (arg2: number) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ +>() => { return () => ({ stuff2: 42, consume2: (arg2) => {}, }); } : () => () => { stuff2: number; consume2: (arg2: number) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ + + return () => ({ +>() => ({ stuff2: 42, consume2: (arg2) => {}, }) : () => { stuff2: number; consume2: (arg2: number) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ +>({ stuff2: 42, consume2: (arg2) => {}, }) : { stuff2: number; consume2: (arg2: number) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ +>{ stuff2: 42, consume2: (arg2) => {}, } : { stuff2: number; consume2: (arg2: number) => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ + + stuff2: 42, +>stuff2 : number +> : ^^^^^^ +>42 : 42 +> : ^^ + + consume2: (arg2) => {}, +>consume2 : (arg2: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>(arg2) => {} : (arg2: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>arg2 : number +> : ^^^^^^ + + }); + }, +})); + +const res6 = test1((_something) => ({ +>res6 : [string, number] +> : ^^^^^^^^^^^^^^^^ +>test1((_something) => ({ consume: () => { return () => ({ consume2: (arg2) => {}, stuff2: 42, }); }, stuff: "foo",})) : [string, number] +> : ^^^^^^^^^^^^^^^^ +>test1 : (fn: Fn1) => [T, T2] +> : ^ ^^ ^^ ^^ ^^^^^ +>(_something) => ({ consume: () => { return () => ({ consume2: (arg2) => {}, stuff2: 42, }); }, stuff: "foo",}) : (_something: unknown) => { consume: () => () => { consume2: (arg2: number) => void; stuff2: number; }; stuff: string; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>_something : unknown +> : ^^^^^^^ +>({ consume: () => { return () => ({ consume2: (arg2) => {}, stuff2: 42, }); }, stuff: "foo",}) : { consume: () => () => { consume2: (arg2: number) => void; stuff2: number; }; stuff: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ consume: () => { return () => ({ consume2: (arg2) => {}, stuff2: 42, }); }, stuff: "foo",} : { consume: () => () => { consume2: (arg2: number) => void; stuff2: number; }; stuff: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + consume: () => { +>consume : () => () => { consume2: (arg2: number) => void; stuff2: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>() => { return () => ({ consume2: (arg2) => {}, stuff2: 42, }); } : () => () => { consume2: (arg2: number) => void; stuff2: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + return () => ({ +>() => ({ consume2: (arg2) => {}, stuff2: 42, }) : () => { consume2: (arg2: number) => void; stuff2: number; } +> : ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>({ consume2: (arg2) => {}, stuff2: 42, }) : { consume2: (arg2: number) => void; stuff2: number; } +> : ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ consume2: (arg2) => {}, stuff2: 42, } : { consume2: (arg2: number) => void; stuff2: number; } +> : ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + consume2: (arg2) => {}, +>consume2 : (arg2: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>(arg2) => {} : (arg2: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>arg2 : number +> : ^^^^^^ + + stuff2: 42, +>stuff2 : number +> : ^^^^^^ +>42 : 42 +> : ^^ + + }); + }, + stuff: "foo", +>stuff : string +> : ^^^^^^ +>"foo" : "foo" +> : ^^^^^ + +})); + +const res7 = test1((_something) => ({ +>res7 : [string, number] +> : ^^^^^^^^^^^^^^^^ +>test1((_something) => ({ stuff: "foo", consume: () => { return () => ({ stuff2: 42, consume2: () => {}, }); },})) : [string, number] +> : ^^^^^^^^^^^^^^^^ +>test1 : (fn: Fn1) => [T, T2] +> : ^ ^^ ^^ ^^ ^^^^^ +>(_something) => ({ stuff: "foo", consume: () => { return () => ({ stuff2: 42, consume2: () => {}, }); },}) : (_something: unknown) => { stuff: string; consume: () => () => { stuff2: number; consume2: () => void; }; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>_something : unknown +> : ^^^^^^^ +>({ stuff: "foo", consume: () => { return () => ({ stuff2: 42, consume2: () => {}, }); },}) : { stuff: string; consume: () => () => { stuff2: number; consume2: () => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ stuff: "foo", consume: () => { return () => ({ stuff2: 42, consume2: () => {}, }); },} : { stuff: string; consume: () => () => { stuff2: number; consume2: () => void; }; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + stuff: "foo", +>stuff : string +> : ^^^^^^ +>"foo" : "foo" +> : ^^^^^ + + consume: () => { +>consume : () => () => { stuff2: number; consume2: () => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>() => { return () => ({ stuff2: 42, consume2: () => {}, }); } : () => () => { stuff2: number; consume2: () => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + return () => ({ +>() => ({ stuff2: 42, consume2: () => {}, }) : () => { stuff2: number; consume2: () => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>({ stuff2: 42, consume2: () => {}, }) : { stuff2: number; consume2: () => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ stuff2: 42, consume2: () => {}, } : { stuff2: number; consume2: () => void; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + stuff2: 42, +>stuff2 : number +> : ^^^^^^ +>42 : 42 +> : ^^ + + consume2: () => {}, +>consume2 : () => void +> : ^^^^^^^^^^ +>() => {} : () => void +> : ^^^^^^^^^^ + + }); + }, +})); + +const res8 = test1((_something) => ({ +>res8 : [string, number] +> : ^^^^^^^^^^^^^^^^ +>test1((_something) => ({ consume: () => { return () => ({ consume2: () => {}, stuff2: 42, }); }, stuff: "foo",})) : [string, number] +> : ^^^^^^^^^^^^^^^^ +>test1 : (fn: Fn1) => [T, T2] +> : ^ ^^ ^^ ^^ ^^^^^ +>(_something) => ({ consume: () => { return () => ({ consume2: () => {}, stuff2: 42, }); }, stuff: "foo",}) : (_something: unknown) => { consume: () => () => { consume2: () => void; stuff2: number; }; stuff: string; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>_something : unknown +> : ^^^^^^^ +>({ consume: () => { return () => ({ consume2: () => {}, stuff2: 42, }); }, stuff: "foo",}) : { consume: () => () => { consume2: () => void; stuff2: number; }; stuff: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ consume: () => { return () => ({ consume2: () => {}, stuff2: 42, }); }, stuff: "foo",} : { consume: () => () => { consume2: () => void; stuff2: number; }; stuff: string; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + consume: () => { +>consume : () => () => { consume2: () => void; stuff2: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>() => { return () => ({ consume2: () => {}, stuff2: 42, }); } : () => () => { consume2: () => void; stuff2: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + return () => ({ +>() => ({ consume2: () => {}, stuff2: 42, }) : () => { consume2: () => void; stuff2: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>({ consume2: () => {}, stuff2: 42, }) : { consume2: () => void; stuff2: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +>{ consume2: () => {}, stuff2: 42, } : { consume2: () => void; stuff2: number; } +> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + + consume2: () => {}, +>consume2 : () => void +> : ^^^^^^^^^^ +>() => {} : () => void +> : ^^^^^^^^^^ + + stuff2: 42, +>stuff2 : number +> : ^^^^^^ +>42 : 42 +> : ^^ + + }); + }, + stuff: "foo", +>stuff : string +> : ^^^^^^ +>"foo" : "foo" +> : ^^^^^ + +})); + diff --git a/tests/baselines/reference/intraExpressionInferencesInContextSensitive1.js b/tests/baselines/reference/intraExpressionInferencesInContextSensitive1.js index 760d687ebc55d..3da93cbc3d46b 100644 --- a/tests/baselines/reference/intraExpressionInferencesInContextSensitive1.js +++ b/tests/baselines/reference/intraExpressionInferencesInContextSensitive1.js @@ -38,6 +38,36 @@ const stepResult = step((_something) => ({ return { test }; }, })); + +type Fn1 = (anything: unknown) => { + produce: (arg: number) => T; + consume: (arg: T) => (anything: unknown) => { + produce2: (arg: number) => T2; + consume2: (arg: T2) => void; + }; +}; + +declare function test1(fn: Fn1): [T, T2]; + +const res1 = test1((_something) => ({ + produce: (input) => "foo", + consume: (arg) => { + return (_something) => ({ + produce2: (input) => 42, + consume2: (arg2) => {}, + }); + }, +})); + +const res2 = test1((_something) => ({ + produce: (input) => "foo", + consume: (arg) => { + return () => ({ + produce2: (input) => 42, + consume2: (arg2) => {}, + }); + }, +})); //// [intraExpressionInferencesInContextSensitive1.js] @@ -61,6 +91,24 @@ var stepResult = step(function (_something) { return ({ return { test: test }; }, }); }); +var res1 = test1(function (_something) { return ({ + produce: function (input) { return "foo"; }, + consume: function (arg) { + return function (_something) { return ({ + produce2: function (input) { return 42; }, + consume2: function (arg2) { }, + }); }; + }, +}); }); +var res2 = test1(function (_something) { return ({ + produce: function (input) { return "foo"; }, + consume: function (arg) { + return function () { return ({ + produce2: function (input) { return 42; }, + consume2: function (arg2) { }, + }); }; + }, +}); }); //// [intraExpressionInferencesInContextSensitive1.d.ts] @@ -78,3 +126,13 @@ declare function step(stepVal: StepFunction; +type Fn1 = (anything: unknown) => { + produce: (arg: number) => T; + consume: (arg: T) => (anything: unknown) => { + produce2: (arg: number) => T2; + consume2: (arg: T2) => void; + }; +}; +declare function test1(fn: Fn1): [T, T2]; +declare const res1: [string, number]; +declare const res2: [string, number]; diff --git a/tests/baselines/reference/intraExpressionInferencesInContextSensitive1.symbols b/tests/baselines/reference/intraExpressionInferencesInContextSensitive1.symbols index 6b124f51f738c..1452767c32b22 100644 --- a/tests/baselines/reference/intraExpressionInferencesInContextSensitive1.symbols +++ b/tests/baselines/reference/intraExpressionInferencesInContextSensitive1.symbols @@ -118,3 +118,98 @@ const stepResult = step((_something) => ({ }, })); +type Fn1 = (anything: unknown) => { +>Fn1 : Symbol(Fn1, Decl(intraExpressionInferencesInContextSensitive1.ts, 36, 4)) +>T : Symbol(T, Decl(intraExpressionInferencesInContextSensitive1.ts, 38, 9)) +>T2 : Symbol(T2, Decl(intraExpressionInferencesInContextSensitive1.ts, 38, 11)) +>anything : Symbol(anything, Decl(intraExpressionInferencesInContextSensitive1.ts, 38, 19)) + + produce: (arg: number) => T; +>produce : Symbol(produce, Decl(intraExpressionInferencesInContextSensitive1.ts, 38, 42)) +>arg : Symbol(arg, Decl(intraExpressionInferencesInContextSensitive1.ts, 39, 12)) +>T : Symbol(T, Decl(intraExpressionInferencesInContextSensitive1.ts, 38, 9)) + + consume: (arg: T) => (anything: unknown) => { +>consume : Symbol(consume, Decl(intraExpressionInferencesInContextSensitive1.ts, 39, 30)) +>arg : Symbol(arg, Decl(intraExpressionInferencesInContextSensitive1.ts, 40, 12)) +>T : Symbol(T, Decl(intraExpressionInferencesInContextSensitive1.ts, 38, 9)) +>anything : Symbol(anything, Decl(intraExpressionInferencesInContextSensitive1.ts, 40, 24)) + + produce2: (arg: number) => T2; +>produce2 : Symbol(produce2, Decl(intraExpressionInferencesInContextSensitive1.ts, 40, 47)) +>arg : Symbol(arg, Decl(intraExpressionInferencesInContextSensitive1.ts, 41, 15)) +>T2 : Symbol(T2, Decl(intraExpressionInferencesInContextSensitive1.ts, 38, 11)) + + consume2: (arg: T2) => void; +>consume2 : Symbol(consume2, Decl(intraExpressionInferencesInContextSensitive1.ts, 41, 34)) +>arg : Symbol(arg, Decl(intraExpressionInferencesInContextSensitive1.ts, 42, 15)) +>T2 : Symbol(T2, Decl(intraExpressionInferencesInContextSensitive1.ts, 38, 11)) + + }; +}; + +declare function test1(fn: Fn1): [T, T2]; +>test1 : Symbol(test1, Decl(intraExpressionInferencesInContextSensitive1.ts, 44, 2)) +>T : Symbol(T, Decl(intraExpressionInferencesInContextSensitive1.ts, 46, 23)) +>T2 : Symbol(T2, Decl(intraExpressionInferencesInContextSensitive1.ts, 46, 25)) +>fn : Symbol(fn, Decl(intraExpressionInferencesInContextSensitive1.ts, 46, 30)) +>Fn1 : Symbol(Fn1, Decl(intraExpressionInferencesInContextSensitive1.ts, 36, 4)) +>T : Symbol(T, Decl(intraExpressionInferencesInContextSensitive1.ts, 46, 23)) +>T2 : Symbol(T2, Decl(intraExpressionInferencesInContextSensitive1.ts, 46, 25)) +>T : Symbol(T, Decl(intraExpressionInferencesInContextSensitive1.ts, 46, 23)) +>T2 : Symbol(T2, Decl(intraExpressionInferencesInContextSensitive1.ts, 46, 25)) + +const res1 = test1((_something) => ({ +>res1 : Symbol(res1, Decl(intraExpressionInferencesInContextSensitive1.ts, 48, 5)) +>test1 : Symbol(test1, Decl(intraExpressionInferencesInContextSensitive1.ts, 44, 2)) +>_something : Symbol(_something, Decl(intraExpressionInferencesInContextSensitive1.ts, 48, 20)) + + produce: (input) => "foo", +>produce : Symbol(produce, Decl(intraExpressionInferencesInContextSensitive1.ts, 48, 37)) +>input : Symbol(input, Decl(intraExpressionInferencesInContextSensitive1.ts, 49, 12)) + + consume: (arg) => { +>consume : Symbol(consume, Decl(intraExpressionInferencesInContextSensitive1.ts, 49, 28)) +>arg : Symbol(arg, Decl(intraExpressionInferencesInContextSensitive1.ts, 50, 12)) + + return (_something) => ({ +>_something : Symbol(_something, Decl(intraExpressionInferencesInContextSensitive1.ts, 51, 12)) + + produce2: (input) => 42, +>produce2 : Symbol(produce2, Decl(intraExpressionInferencesInContextSensitive1.ts, 51, 29)) +>input : Symbol(input, Decl(intraExpressionInferencesInContextSensitive1.ts, 52, 17)) + + consume2: (arg2) => {}, +>consume2 : Symbol(consume2, Decl(intraExpressionInferencesInContextSensitive1.ts, 52, 30)) +>arg2 : Symbol(arg2, Decl(intraExpressionInferencesInContextSensitive1.ts, 53, 17)) + + }); + }, +})); + +const res2 = test1((_something) => ({ +>res2 : Symbol(res2, Decl(intraExpressionInferencesInContextSensitive1.ts, 58, 5)) +>test1 : Symbol(test1, Decl(intraExpressionInferencesInContextSensitive1.ts, 44, 2)) +>_something : Symbol(_something, Decl(intraExpressionInferencesInContextSensitive1.ts, 58, 20)) + + produce: (input) => "foo", +>produce : Symbol(produce, Decl(intraExpressionInferencesInContextSensitive1.ts, 58, 37)) +>input : Symbol(input, Decl(intraExpressionInferencesInContextSensitive1.ts, 59, 12)) + + consume: (arg) => { +>consume : Symbol(consume, Decl(intraExpressionInferencesInContextSensitive1.ts, 59, 28)) +>arg : Symbol(arg, Decl(intraExpressionInferencesInContextSensitive1.ts, 60, 12)) + + return () => ({ + produce2: (input) => 42, +>produce2 : Symbol(produce2, Decl(intraExpressionInferencesInContextSensitive1.ts, 61, 19)) +>input : Symbol(input, Decl(intraExpressionInferencesInContextSensitive1.ts, 62, 17)) + + consume2: (arg2) => {}, +>consume2 : Symbol(consume2, Decl(intraExpressionInferencesInContextSensitive1.ts, 62, 30)) +>arg2 : Symbol(arg2, Decl(intraExpressionInferencesInContextSensitive1.ts, 63, 17)) + + }); + }, +})); + diff --git a/tests/baselines/reference/intraExpressionInferencesInContextSensitive1.types b/tests/baselines/reference/intraExpressionInferencesInContextSensitive1.types index 1903b5f3f8593..5e5add9eab0d3 100644 --- a/tests/baselines/reference/intraExpressionInferencesInContextSensitive1.types +++ b/tests/baselines/reference/intraExpressionInferencesInContextSensitive1.types @@ -180,3 +180,174 @@ const stepResult = step((_something) => ({ }, })); +type Fn1 = (anything: unknown) => { +>Fn1 : Fn1 +> : ^^^^^^^^^^ +>anything : unknown +> : ^^^^^^^ + + produce: (arg: number) => T; +>produce : (arg: number) => T +> : ^ ^^ ^^^^^ +>arg : number +> : ^^^^^^ + + consume: (arg: T) => (anything: unknown) => { +>consume : (arg: T) => (anything: unknown) => { produce2: (arg: number) => T2; consume2: (arg: T2) => void; } +> : ^ ^^ ^^^^^ +>arg : T +> : ^ +>anything : unknown +> : ^^^^^^^ + + produce2: (arg: number) => T2; +>produce2 : (arg: number) => T2 +> : ^ ^^ ^^^^^ +>arg : number +> : ^^^^^^ + + consume2: (arg: T2) => void; +>consume2 : (arg: T2) => void +> : ^ ^^ ^^^^^ +>arg : T2 +> : ^^ + + }; +}; + +declare function test1(fn: Fn1): [T, T2]; +>test1 : (fn: Fn1) => [T, T2] +> : ^ ^^ ^^ ^^ ^^^^^ +>fn : Fn1 +> : ^^^^^^^^^^ + +const res1 = test1((_something) => ({ +>res1 : [string, number] +> : ^^^^^^^^^^^^^^^^ +>test1((_something) => ({ produce: (input) => "foo", consume: (arg) => { return (_something) => ({ produce2: (input) => 42, consume2: (arg2) => {}, }); },})) : [string, number] +> : ^^^^^^^^^^^^^^^^ +>test1 : (fn: Fn1) => [T, T2] +> : ^ ^^ ^^ ^^ ^^^^^ +>(_something) => ({ produce: (input) => "foo", consume: (arg) => { return (_something) => ({ produce2: (input) => 42, consume2: (arg2) => {}, }); },}) : (_something: unknown) => { produce: (input: number) => string; consume: (arg: string) => (_something: unknown) => { produce2: (input: number) => number; consume2: (arg2: number) => void; }; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ +>_something : unknown +> : ^^^^^^^ +>({ produce: (input) => "foo", consume: (arg) => { return (_something) => ({ produce2: (input) => 42, consume2: (arg2) => {}, }); },}) : { produce: (input: number) => string; consume: (arg: string) => (_something: unknown) => { produce2: (input: number) => number; consume2: (arg2: number) => void; }; } +> : ^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ +>{ produce: (input) => "foo", consume: (arg) => { return (_something) => ({ produce2: (input) => 42, consume2: (arg2) => {}, }); },} : { produce: (input: number) => string; consume: (arg: string) => (_something: unknown) => { produce2: (input: number) => number; consume2: (arg2: number) => void; }; } +> : ^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ + + produce: (input) => "foo", +>produce : (input: number) => string +> : ^ ^^^^^^^^^^^^^^^^^^^ +>(input) => "foo" : (input: number) => string +> : ^ ^^^^^^^^^^^^^^^^^^^ +>input : number +> : ^^^^^^ +>"foo" : "foo" +> : ^^^^^ + + consume: (arg) => { +>consume : (arg: string) => (_something: unknown) => { produce2: (input: number) => number; consume2: (arg2: number) => void; } +> : ^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ +>(arg) => { return (_something) => ({ produce2: (input) => 42, consume2: (arg2) => {}, }); } : (arg: string) => (_something: unknown) => { produce2: (input: number) => number; consume2: (arg2: number) => void; } +> : ^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ +>arg : string +> : ^^^^^^ + + return (_something) => ({ +>(_something) => ({ produce2: (input) => 42, consume2: (arg2) => {}, }) : (_something: unknown) => { produce2: (input: number) => number; consume2: (arg2: number) => void; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ +>_something : unknown +> : ^^^^^^^ +>({ produce2: (input) => 42, consume2: (arg2) => {}, }) : { produce2: (input: number) => number; consume2: (arg2: number) => void; } +> : ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ +>{ produce2: (input) => 42, consume2: (arg2) => {}, } : { produce2: (input: number) => number; consume2: (arg2: number) => void; } +> : ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ + + produce2: (input) => 42, +>produce2 : (input: number) => number +> : ^ ^^^^^^^^^^^^^^^^^^^ +>(input) => 42 : (input: number) => number +> : ^ ^^^^^^^^^^^^^^^^^^^ +>input : number +> : ^^^^^^ +>42 : 42 +> : ^^ + + consume2: (arg2) => {}, +>consume2 : (arg2: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>(arg2) => {} : (arg2: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>arg2 : number +> : ^^^^^^ + + }); + }, +})); + +const res2 = test1((_something) => ({ +>res2 : [string, number] +> : ^^^^^^^^^^^^^^^^ +>test1((_something) => ({ produce: (input) => "foo", consume: (arg) => { return () => ({ produce2: (input) => 42, consume2: (arg2) => {}, }); },})) : [string, number] +> : ^^^^^^^^^^^^^^^^ +>test1 : (fn: Fn1) => [T, T2] +> : ^ ^^ ^^ ^^ ^^^^^ +>(_something) => ({ produce: (input) => "foo", consume: (arg) => { return () => ({ produce2: (input) => 42, consume2: (arg2) => {}, }); },}) : (_something: unknown) => { produce: (input: number) => string; consume: (arg: string) => () => { produce2: (input: number) => number; consume2: (arg2: number) => void; }; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ +>_something : unknown +> : ^^^^^^^ +>({ produce: (input) => "foo", consume: (arg) => { return () => ({ produce2: (input) => 42, consume2: (arg2) => {}, }); },}) : { produce: (input: number) => string; consume: (arg: string) => () => { produce2: (input: number) => number; consume2: (arg2: number) => void; }; } +> : ^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ +>{ produce: (input) => "foo", consume: (arg) => { return () => ({ produce2: (input) => 42, consume2: (arg2) => {}, }); },} : { produce: (input: number) => string; consume: (arg: string) => () => { produce2: (input: number) => number; consume2: (arg2: number) => void; }; } +> : ^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^ + + produce: (input) => "foo", +>produce : (input: number) => string +> : ^ ^^^^^^^^^^^^^^^^^^^ +>(input) => "foo" : (input: number) => string +> : ^ ^^^^^^^^^^^^^^^^^^^ +>input : number +> : ^^^^^^ +>"foo" : "foo" +> : ^^^^^ + + consume: (arg) => { +>consume : (arg: string) => () => { produce2: (input: number) => number; consume2: (arg2: number) => void; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ +>(arg) => { return () => ({ produce2: (input) => 42, consume2: (arg2) => {}, }); } : (arg: string) => () => { produce2: (input: number) => number; consume2: (arg2: number) => void; } +> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ +>arg : string +> : ^^^^^^ + + return () => ({ +>() => ({ produce2: (input) => 42, consume2: (arg2) => {}, }) : () => { produce2: (input: number) => number; consume2: (arg2: number) => void; } +> : ^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ +>({ produce2: (input) => 42, consume2: (arg2) => {}, }) : { produce2: (input: number) => number; consume2: (arg2: number) => void; } +> : ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ +>{ produce2: (input) => 42, consume2: (arg2) => {}, } : { produce2: (input: number) => number; consume2: (arg2: number) => void; } +> : ^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^ + + produce2: (input) => 42, +>produce2 : (input: number) => number +> : ^ ^^^^^^^^^^^^^^^^^^^ +>(input) => 42 : (input: number) => number +> : ^ ^^^^^^^^^^^^^^^^^^^ +>input : number +> : ^^^^^^ +>42 : 42 +> : ^^ + + consume2: (arg2) => {}, +>consume2 : (arg2: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>(arg2) => {} : (arg2: number) => void +> : ^ ^^^^^^^^^^^^^^^^^ +>arg2 : number +> : ^^^^^^ + + }); + }, +})); + diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/InferFromReturnsInContextSensitive1.ts b/tests/cases/conformance/types/typeRelationships/typeInference/InferFromReturnsInContextSensitive1.ts index 0a76276f58b4f..019f7056858d2 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/InferFromReturnsInContextSensitive1.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/InferFromReturnsInContextSensitive1.ts @@ -17,6 +17,11 @@ create((arg) => ({ onEnd: (context) => {}, })); +create((arg) => ({ + onEnd: (context) => {}, + onStart: () => ({ time: new Date() }), +})); + // https://github.com/microsoft/TypeScript/issues/57021 type Schema = Record; @@ -26,13 +31,13 @@ type StepFunction = (anything: unknown) => { readonly toAnswers?: (keys: keyof TSchema) => unknown; }; -function step1( +function step( stepVal: StepFunction, ): StepFunction { return stepVal; } -const stepResult1 = step1((_something) => ({ +const stepResult1 = step((_something) => ({ schema: { attribute: "anything", }, @@ -42,3 +47,104 @@ const stepResult1 = step1((_something) => ({ return { test }; }, })); + +const stepResult2 = step((_something) => ({ + toAnswers: (keys) => { + type Test = string extends typeof keys ? never : "true"; + const test: Test = "true"; // ok + return { test }; + }, + schema: { + attribute: "anything", + }, +})); + +type Fn1 = (anything: unknown) => { + stuff: T; + consume: (arg: T) => (anything: unknown) => { + stuff2: T2; + consume2: (arg: T2) => void; + }; +}; + +declare function test1(fn: Fn1): [T, T2]; + +const res1 = test1((_something) => ({ + stuff: "foo", + consume: (arg) => { + return (_something) => ({ + stuff2: 42, + consume2: (arg2) => {}, + }); + }, +})); + +const res2 = test1((_something) => ({ + consume: (arg) => { + return (_something) => ({ + consume2: (arg2) => {}, + stuff2: 42, + }); + }, + stuff: "foo", +})); + +const res3 = test1((_something) => ({ + stuff: "foo", + consume: () => { + return (_something) => ({ + stuff2: 42, + consume2: (arg2) => {}, + }); + }, +})); + +const res4 = test1((_something) => ({ + consume: () => { + return (_something) => ({ + consume2: (arg2) => {}, + stuff2: 42, + }); + }, + stuff: "foo", +})); + +const res5 = test1((_something) => ({ + stuff: "foo", + consume: () => { + return () => ({ + stuff2: 42, + consume2: (arg2) => {}, + }); + }, +})); + +const res6 = test1((_something) => ({ + consume: () => { + return () => ({ + consume2: (arg2) => {}, + stuff2: 42, + }); + }, + stuff: "foo", +})); + +const res7 = test1((_something) => ({ + stuff: "foo", + consume: () => { + return () => ({ + stuff2: 42, + consume2: () => {}, + }); + }, +})); + +const res8 = test1((_something) => ({ + consume: () => { + return () => ({ + consume2: () => {}, + stuff2: 42, + }); + }, + stuff: "foo", +})); diff --git a/tests/cases/conformance/types/typeRelationships/typeInference/intraExpressionInferencesInContextSensitive1.ts b/tests/cases/conformance/types/typeRelationships/typeInference/intraExpressionInferencesInContextSensitive1.ts index 927d7fd989499..21a4631c1ae62 100644 --- a/tests/cases/conformance/types/typeRelationships/typeInference/intraExpressionInferencesInContextSensitive1.ts +++ b/tests/cases/conformance/types/typeRelationships/typeInference/intraExpressionInferencesInContextSensitive1.ts @@ -38,3 +38,33 @@ const stepResult = step((_something) => ({ return { test }; }, })); + +type Fn1 = (anything: unknown) => { + produce: (arg: number) => T; + consume: (arg: T) => (anything: unknown) => { + produce2: (arg: number) => T2; + consume2: (arg: T2) => void; + }; +}; + +declare function test1(fn: Fn1): [T, T2]; + +const res1 = test1((_something) => ({ + produce: (input) => "foo", + consume: (arg) => { + return (_something) => ({ + produce2: (input) => 42, + consume2: (arg2) => {}, + }); + }, +})); + +const res2 = test1((_something) => ({ + produce: (input) => "foo", + consume: (arg) => { + return () => ({ + produce2: (input) => 42, + consume2: (arg2) => {}, + }); + }, +}));