Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andarist committed Jan 6, 2025
1 parent c61ea39 commit 23c6c33
Show file tree
Hide file tree
Showing 8 changed files with 1,571 additions and 50 deletions.
220 changes: 215 additions & 5 deletions tests/baselines/reference/InferFromReturnsInContextSensitive1.js
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, unknown>;
Expand All @@ -26,13 +31,13 @@ type StepFunction<TSchema extends Schema = Schema> = (anything: unknown) => {
readonly toAnswers?: (keys: keyof TSchema) => unknown;
};

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

const stepResult1 = step1((_something) => ({
const stepResult1 = step((_something) => ({
schema: {
attribute: "anything",
},
Expand All @@ -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<T, T2> = (anything: unknown) => {
stuff: T;
consume: (arg: T) => (anything: unknown) => {
stuff2: T2;
consume2: (arg: T2) => void;
};
};

declare function test1<T, T2>(fn: Fn1<T, T2>): [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]
Expand All @@ -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",
},
Expand All @@ -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]
Expand All @@ -79,7 +270,26 @@ 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 function step<TSchema extends Schema = Schema>(stepVal: StepFunction<TSchema>): StepFunction<TSchema>;
declare const stepResult1: StepFunction<{
attribute: string;
}>;
declare const stepResult2: StepFunction<{
attribute: string;
}>;
type Fn1<T, T2> = (anything: unknown) => {
stuff: T;
consume: (arg: T) => (anything: unknown) => {
stuff2: T2;
consume2: (arg: T2) => void;
};
};
declare function test1<T, T2>(fn: Fn1<T, T2>): [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];
Loading

0 comments on commit 23c6c33

Please sign in to comment.