|
| 1 | +//// [tests/cases/conformance/types/typeRelationships/typeInference/InferFromReturnsInContextSensitive1.ts] //// |
| 2 | + |
| 3 | +=== InferFromReturnsInContextSensitive1.ts === |
| 4 | +// https://github.com/microsoft/TypeScript/issues/60720 |
| 5 | + |
| 6 | +type Options<TContext> = { |
| 7 | +>Options : Symbol(Options, Decl(InferFromReturnsInContextSensitive1.ts, 0, 0)) |
| 8 | +>TContext : Symbol(TContext, Decl(InferFromReturnsInContextSensitive1.ts, 2, 13)) |
| 9 | + |
| 10 | + onStart?: () => TContext; |
| 11 | +>onStart : Symbol(onStart, Decl(InferFromReturnsInContextSensitive1.ts, 2, 26)) |
| 12 | +>TContext : Symbol(TContext, Decl(InferFromReturnsInContextSensitive1.ts, 2, 13)) |
| 13 | + |
| 14 | + onEnd?: (context: TContext) => void; |
| 15 | +>onEnd : Symbol(onEnd, Decl(InferFromReturnsInContextSensitive1.ts, 3, 27)) |
| 16 | +>context : Symbol(context, Decl(InferFromReturnsInContextSensitive1.ts, 4, 11)) |
| 17 | +>TContext : Symbol(TContext, Decl(InferFromReturnsInContextSensitive1.ts, 2, 13)) |
| 18 | + |
| 19 | +}; |
| 20 | + |
| 21 | +function create<TContext>(builder: (arg: boolean) => Options<TContext>) { |
| 22 | +>create : Symbol(create, Decl(InferFromReturnsInContextSensitive1.ts, 5, 2)) |
| 23 | +>TContext : Symbol(TContext, Decl(InferFromReturnsInContextSensitive1.ts, 7, 16)) |
| 24 | +>builder : Symbol(builder, Decl(InferFromReturnsInContextSensitive1.ts, 7, 26)) |
| 25 | +>arg : Symbol(arg, Decl(InferFromReturnsInContextSensitive1.ts, 7, 36)) |
| 26 | +>Options : Symbol(Options, Decl(InferFromReturnsInContextSensitive1.ts, 0, 0)) |
| 27 | +>TContext : Symbol(TContext, Decl(InferFromReturnsInContextSensitive1.ts, 7, 16)) |
| 28 | + |
| 29 | + return builder(true); |
| 30 | +>builder : Symbol(builder, Decl(InferFromReturnsInContextSensitive1.ts, 7, 26)) |
| 31 | +} |
| 32 | + |
| 33 | +create((arg) => ({ |
| 34 | +>create : Symbol(create, Decl(InferFromReturnsInContextSensitive1.ts, 5, 2)) |
| 35 | +>arg : Symbol(arg, Decl(InferFromReturnsInContextSensitive1.ts, 11, 8)) |
| 36 | + |
| 37 | + onStart: () => ({ time: new Date() }), |
| 38 | +>onStart : Symbol(onStart, Decl(InferFromReturnsInContextSensitive1.ts, 11, 18)) |
| 39 | +>time : Symbol(time, Decl(InferFromReturnsInContextSensitive1.ts, 12, 19)) |
| 40 | +>Date : Symbol(Date, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.scripthost.d.ts, --, --)) |
| 41 | + |
| 42 | + onEnd: (context) => {}, |
| 43 | +>onEnd : Symbol(onEnd, Decl(InferFromReturnsInContextSensitive1.ts, 12, 40)) |
| 44 | +>context : Symbol(context, Decl(InferFromReturnsInContextSensitive1.ts, 13, 10)) |
| 45 | + |
| 46 | +})); |
| 47 | + |
| 48 | +// https://github.com/microsoft/TypeScript/issues/57021 |
| 49 | + |
| 50 | +type Schema = Record<string, unknown>; |
| 51 | +>Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 14, 4)) |
| 52 | +>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --)) |
| 53 | + |
| 54 | +type StepFunction<TSchema extends Schema = Schema> = (anything: unknown) => { |
| 55 | +>StepFunction : Symbol(StepFunction, Decl(InferFromReturnsInContextSensitive1.ts, 18, 38)) |
| 56 | +>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 20, 18)) |
| 57 | +>Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 14, 4)) |
| 58 | +>Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 14, 4)) |
| 59 | +>anything : Symbol(anything, Decl(InferFromReturnsInContextSensitive1.ts, 20, 54)) |
| 60 | + |
| 61 | + readonly schema: TSchema; |
| 62 | +>schema : Symbol(schema, Decl(InferFromReturnsInContextSensitive1.ts, 20, 77)) |
| 63 | +>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 20, 18)) |
| 64 | + |
| 65 | + readonly toAnswers?: (keys: keyof TSchema) => unknown; |
| 66 | +>toAnswers : Symbol(toAnswers, Decl(InferFromReturnsInContextSensitive1.ts, 21, 27)) |
| 67 | +>keys : Symbol(keys, Decl(InferFromReturnsInContextSensitive1.ts, 22, 24)) |
| 68 | +>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 20, 18)) |
| 69 | + |
| 70 | +}; |
| 71 | + |
| 72 | +function step1<TSchema extends Schema = Schema>( |
| 73 | +>step1 : Symbol(step1, Decl(InferFromReturnsInContextSensitive1.ts, 23, 2)) |
| 74 | +>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 25, 15)) |
| 75 | +>Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 14, 4)) |
| 76 | +>Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 14, 4)) |
| 77 | + |
| 78 | + stepVal: StepFunction<TSchema>, |
| 79 | +>stepVal : Symbol(stepVal, Decl(InferFromReturnsInContextSensitive1.ts, 25, 48)) |
| 80 | +>StepFunction : Symbol(StepFunction, Decl(InferFromReturnsInContextSensitive1.ts, 18, 38)) |
| 81 | +>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 25, 15)) |
| 82 | + |
| 83 | +): StepFunction<TSchema> { |
| 84 | +>StepFunction : Symbol(StepFunction, Decl(InferFromReturnsInContextSensitive1.ts, 18, 38)) |
| 85 | +>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 25, 15)) |
| 86 | + |
| 87 | + return stepVal; |
| 88 | +>stepVal : Symbol(stepVal, Decl(InferFromReturnsInContextSensitive1.ts, 25, 48)) |
| 89 | +} |
| 90 | + |
| 91 | +const stepResult1 = step1((_something) => ({ |
| 92 | +>stepResult1 : Symbol(stepResult1, Decl(InferFromReturnsInContextSensitive1.ts, 31, 5)) |
| 93 | +>step1 : Symbol(step1, Decl(InferFromReturnsInContextSensitive1.ts, 23, 2)) |
| 94 | +>_something : Symbol(_something, Decl(InferFromReturnsInContextSensitive1.ts, 31, 27)) |
| 95 | + |
| 96 | + schema: { |
| 97 | +>schema : Symbol(schema, Decl(InferFromReturnsInContextSensitive1.ts, 31, 44)) |
| 98 | + |
| 99 | + attribute: "anything", |
| 100 | +>attribute : Symbol(attribute, Decl(InferFromReturnsInContextSensitive1.ts, 32, 11)) |
| 101 | + |
| 102 | + }, |
| 103 | + toAnswers: (keys) => { |
| 104 | +>toAnswers : Symbol(toAnswers, Decl(InferFromReturnsInContextSensitive1.ts, 34, 4)) |
| 105 | +>keys : Symbol(keys, Decl(InferFromReturnsInContextSensitive1.ts, 35, 14)) |
| 106 | + |
| 107 | + type Test = string extends typeof keys ? never : "true"; |
| 108 | +>Test : Symbol(Test, Decl(InferFromReturnsInContextSensitive1.ts, 35, 24)) |
| 109 | +>keys : Symbol(keys, Decl(InferFromReturnsInContextSensitive1.ts, 35, 14)) |
| 110 | + |
| 111 | + const test: Test = "true"; // ok |
| 112 | +>test : Symbol(test, Decl(InferFromReturnsInContextSensitive1.ts, 37, 9)) |
| 113 | +>Test : Symbol(Test, Decl(InferFromReturnsInContextSensitive1.ts, 35, 24)) |
| 114 | + |
| 115 | + return { test }; |
| 116 | +>test : Symbol(test, Decl(InferFromReturnsInContextSensitive1.ts, 38, 12)) |
| 117 | + |
| 118 | + }, |
| 119 | +})); |
| 120 | + |
0 commit comments