Skip to content

Commit

Permalink
split tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Jan 6, 2025
1 parent c671b45 commit c61ea39
Show file tree
Hide file tree
Showing 8 changed files with 535 additions and 479 deletions.
85 changes: 85 additions & 0 deletions tests/baselines/reference/InferFromReturnsInContextSensitive1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//// [tests/cases/conformance/types/typeRelationships/typeInference/InferFromReturnsInContextSensitive1.ts] ////

//// [InferFromReturnsInContextSensitive1.ts]
// https://github.com/microsoft/TypeScript/issues/60720

type Options<TContext> = {
onStart?: () => TContext;
onEnd?: (context: TContext) => void;
};

function create<TContext>(builder: (arg: boolean) => Options<TContext>) {
return builder(true);
}

create((arg) => ({
onStart: () => ({ time: new Date() }),
onEnd: (context) => {},
}));

// https://github.com/microsoft/TypeScript/issues/57021

type Schema = Record<string, unknown>;

type StepFunction<TSchema extends Schema = Schema> = (anything: unknown) => {
readonly schema: TSchema;
readonly toAnswers?: (keys: keyof TSchema) => unknown;
};

function step1<TSchema extends Schema = Schema>(
stepVal: StepFunction<TSchema>,
): StepFunction<TSchema> {
return stepVal;
}

const stepResult1 = step1((_something) => ({
schema: {
attribute: "anything",
},
toAnswers: (keys) => {
type Test = string extends typeof keys ? never : "true";
const test: Test = "true"; // ok
return { test };
},
}));


//// [InferFromReturnsInContextSensitive1.js]
"use strict";
// https://github.com/microsoft/TypeScript/issues/60720
function create(builder) {
return builder(true);
}
create(function (arg) { return ({
onStart: function () { return ({ time: new Date() }); },
onEnd: function (context) { },
}); });
function step1(stepVal) {
return stepVal;
}
var stepResult1 = step1(function (_something) { return ({
schema: {
attribute: "anything",
},
toAnswers: function (keys) {
var test = "true"; // ok
return { test: test };
},
}); });


//// [InferFromReturnsInContextSensitive1.d.ts]
type Options<TContext> = {
onStart?: () => TContext;
onEnd?: (context: TContext) => void;
};
declare function create<TContext>(builder: (arg: boolean) => Options<TContext>): Options<TContext>;
type Schema = Record<string, unknown>;
type StepFunction<TSchema extends Schema = Schema> = (anything: unknown) => {
readonly schema: TSchema;
readonly toAnswers?: (keys: keyof TSchema) => unknown;
};
declare function step1<TSchema extends Schema = Schema>(stepVal: StepFunction<TSchema>): StepFunction<TSchema>;
declare const stepResult1: StepFunction<{
attribute: string;
}>;
120 changes: 120 additions & 0 deletions tests/baselines/reference/InferFromReturnsInContextSensitive1.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
//// [tests/cases/conformance/types/typeRelationships/typeInference/InferFromReturnsInContextSensitive1.ts] ////

=== InferFromReturnsInContextSensitive1.ts ===
// https://github.com/microsoft/TypeScript/issues/60720

type Options<TContext> = {
>Options : Symbol(Options, Decl(InferFromReturnsInContextSensitive1.ts, 0, 0))
>TContext : Symbol(TContext, Decl(InferFromReturnsInContextSensitive1.ts, 2, 13))

onStart?: () => TContext;
>onStart : Symbol(onStart, Decl(InferFromReturnsInContextSensitive1.ts, 2, 26))
>TContext : Symbol(TContext, Decl(InferFromReturnsInContextSensitive1.ts, 2, 13))

onEnd?: (context: TContext) => void;
>onEnd : Symbol(onEnd, Decl(InferFromReturnsInContextSensitive1.ts, 3, 27))
>context : Symbol(context, Decl(InferFromReturnsInContextSensitive1.ts, 4, 11))
>TContext : Symbol(TContext, Decl(InferFromReturnsInContextSensitive1.ts, 2, 13))

};

function create<TContext>(builder: (arg: boolean) => Options<TContext>) {
>create : Symbol(create, Decl(InferFromReturnsInContextSensitive1.ts, 5, 2))
>TContext : Symbol(TContext, Decl(InferFromReturnsInContextSensitive1.ts, 7, 16))
>builder : Symbol(builder, Decl(InferFromReturnsInContextSensitive1.ts, 7, 26))
>arg : Symbol(arg, Decl(InferFromReturnsInContextSensitive1.ts, 7, 36))
>Options : Symbol(Options, Decl(InferFromReturnsInContextSensitive1.ts, 0, 0))
>TContext : Symbol(TContext, Decl(InferFromReturnsInContextSensitive1.ts, 7, 16))

return builder(true);
>builder : Symbol(builder, Decl(InferFromReturnsInContextSensitive1.ts, 7, 26))
}

create((arg) => ({
>create : Symbol(create, Decl(InferFromReturnsInContextSensitive1.ts, 5, 2))
>arg : Symbol(arg, Decl(InferFromReturnsInContextSensitive1.ts, 11, 8))

onStart: () => ({ time: new Date() }),
>onStart : Symbol(onStart, Decl(InferFromReturnsInContextSensitive1.ts, 11, 18))
>time : Symbol(time, Decl(InferFromReturnsInContextSensitive1.ts, 12, 19))
>Date : Symbol(Date, Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.es5.d.ts, --, --), Decl(lib.scripthost.d.ts, --, --))

onEnd: (context) => {},
>onEnd : Symbol(onEnd, Decl(InferFromReturnsInContextSensitive1.ts, 12, 40))
>context : Symbol(context, Decl(InferFromReturnsInContextSensitive1.ts, 13, 10))

}));

// https://github.com/microsoft/TypeScript/issues/57021

type Schema = Record<string, unknown>;
>Schema : Symbol(Schema, Decl(InferFromReturnsInContextSensitive1.ts, 14, 4))
>Record : Symbol(Record, Decl(lib.es5.d.ts, --, --))

type StepFunction<TSchema extends Schema = Schema> = (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))

readonly schema: TSchema;
>schema : Symbol(schema, Decl(InferFromReturnsInContextSensitive1.ts, 20, 77))
>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 20, 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))

};

function step1<TSchema extends Schema = Schema>(
>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))

stepVal: StepFunction<TSchema>,
>stepVal : Symbol(stepVal, Decl(InferFromReturnsInContextSensitive1.ts, 25, 48))
>StepFunction : Symbol(StepFunction, Decl(InferFromReturnsInContextSensitive1.ts, 18, 38))
>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 25, 15))

): StepFunction<TSchema> {
>StepFunction : Symbol(StepFunction, Decl(InferFromReturnsInContextSensitive1.ts, 18, 38))
>TSchema : Symbol(TSchema, Decl(InferFromReturnsInContextSensitive1.ts, 25, 15))

return stepVal;
>stepVal : Symbol(stepVal, Decl(InferFromReturnsInContextSensitive1.ts, 25, 48))
}

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))

schema: {
>schema : Symbol(schema, Decl(InferFromReturnsInContextSensitive1.ts, 31, 44))

attribute: "anything",
>attribute : Symbol(attribute, Decl(InferFromReturnsInContextSensitive1.ts, 32, 11))

},
toAnswers: (keys) => {
>toAnswers : Symbol(toAnswers, Decl(InferFromReturnsInContextSensitive1.ts, 34, 4))
>keys : Symbol(keys, Decl(InferFromReturnsInContextSensitive1.ts, 35, 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))

const test: Test = "true"; // ok
>test : Symbol(test, Decl(InferFromReturnsInContextSensitive1.ts, 37, 9))
>Test : Symbol(Test, Decl(InferFromReturnsInContextSensitive1.ts, 35, 24))

return { test };
>test : Symbol(test, Decl(InferFromReturnsInContextSensitive1.ts, 38, 12))

},
}));

174 changes: 174 additions & 0 deletions tests/baselines/reference/InferFromReturnsInContextSensitive1.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
//// [tests/cases/conformance/types/typeRelationships/typeInference/InferFromReturnsInContextSensitive1.ts] ////

=== InferFromReturnsInContextSensitive1.ts ===
// https://github.com/microsoft/TypeScript/issues/60720

type Options<TContext> = {
>Options : Options<TContext>
> : ^^^^^^^^^^^^^^^^^

onStart?: () => TContext;
>onStart : (() => TContext) | undefined
> : ^^^^^^^ ^^^^^^^^^^^^^

onEnd?: (context: TContext) => void;
>onEnd : ((context: TContext) => void) | undefined
> : ^^ ^^ ^^^^^ ^^^^^^^^^^^^^
>context : TContext
> : ^^^^^^^^

};

function create<TContext>(builder: (arg: boolean) => Options<TContext>) {
>create : <TContext>(builder: (arg: boolean) => Options<TContext>) => Options<TContext>
> : ^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^
>builder : (arg: boolean) => Options<TContext>
> : ^ ^^ ^^^^^
>arg : boolean
> : ^^^^^^^

return builder(true);
>builder(true) : Options<TContext>
> : ^^^^^^^^^^^^^^^^^
>builder : (arg: boolean) => Options<TContext>
> : ^ ^^ ^^^^^
>true : true
> : ^^^^
}

create((arg) => ({
>create((arg) => ({ onStart: () => ({ time: new Date() }), onEnd: (context) => {},})) : Options<{ time: Date; }>
> : ^^^^^^^^^^^^^^^^^^^^^^^^
>create : <TContext>(builder: (arg: boolean) => Options<TContext>) => Options<TContext>
> : ^ ^^ ^^ ^^^^^^^^^^^^^^^^^^^^^^
>(arg) => ({ onStart: () => ({ time: new Date() }), onEnd: (context) => {},}) : (arg: boolean) => { onStart: () => { time: Date; }; onEnd: (context: { time: Date; }) => void; }
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>arg : boolean
> : ^^^^^^^
>({ onStart: () => ({ time: new Date() }), onEnd: (context) => {},}) : { onStart: () => { time: Date; }; onEnd: (context: { time: Date; }) => void; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>{ onStart: () => ({ time: new Date() }), onEnd: (context) => {},} : { onStart: () => { time: Date; }; onEnd: (context: { time: Date; }) => void; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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
> : ^^^^^^^^^^^^^^^

onEnd: (context) => {},
>onEnd : (context: { time: Date; }) => void
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
>(context) => {} : (context: { time: Date; }) => void
> : ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^
>context : { time: Date; }
> : ^^^^^^^^^^^^^^^

}));

// https://github.com/microsoft/TypeScript/issues/57021

type Schema = Record<string, unknown>;
>Schema : Schema
> : ^^^^^^

type StepFunction<TSchema extends Schema = Schema> = (anything: unknown) => {
>StepFunction : StepFunction<TSchema>
> : ^^^^^^^^^^^^^^^^^^^^^
>anything : unknown
> : ^^^^^^^

readonly schema: TSchema;
>schema : TSchema
> : ^^^^^^^

readonly toAnswers?: (keys: keyof TSchema) => unknown;
>toAnswers : ((keys: keyof TSchema) => unknown) | undefined
> : ^^ ^^ ^^^^^ ^^^^^^^^^^^^^
>keys : keyof TSchema
> : ^^^^^^^^^^^^^

};

function step1<TSchema extends Schema = Schema>(
>step1 : <TSchema extends Schema = Schema>(stepVal: StepFunction<TSchema>) => StepFunction<TSchema>
> : ^ ^^^^^^^^^ ^^^^^^^^^^^ ^^ ^^^^^

stepVal: StepFunction<TSchema>,
>stepVal : StepFunction<TSchema>
> : ^^^^^^^^^^^^^^^^^^^^^

): StepFunction<TSchema> {
return stepVal;
>stepVal : StepFunction<TSchema>
> : ^^^^^^^^^^^^^^^^^^^^^
}

const stepResult1 = step1((_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 : <TSchema extends Schema = Schema>(stepVal: StepFunction<TSchema>) => StepFunction<TSchema>
> : ^ ^^^^^^^^^ ^^^^^^^^^^^ ^^ ^^^^^
>(_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
> : ^^^^^^^
>({ schema: { attribute: "anything", }, toAnswers: (keys) => { type Test = string extends typeof keys ? never : "true"; const test: Test = "true"; // ok return { test }; },}) : { schema: { attribute: string; }; toAnswers: (keys: "attribute") => { test: "true"; }; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>{ schema: { attribute: "anything", }, toAnswers: (keys) => { type Test = string extends typeof keys ? never : "true"; const test: Test = "true"; // ok return { test }; },} : { schema: { attribute: string; }; toAnswers: (keys: "attribute") => { test: "true"; }; }
> : ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

schema: {
>schema : { attribute: string; }
> : ^^^^^^^^^^^^^^^^^^^^^^
>{ attribute: "anything", } : { attribute: string; }
> : ^^^^^^^^^^^^^^^^^^^^^^

attribute: "anything",
>attribute : string
> : ^^^^^^
>"anything" : "anything"
> : ^^^^^^^^^^

},
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"
> : ^^^^^^

},
}));

Loading

0 comments on commit c61ea39

Please sign in to comment.