Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/named fn params #798

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions packages/inngest/src/components/InngestStepTools.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ describe("run", () => {
});
});

test("types allow named function", () => {
void step.run("", function named() {});
});

test("types returned from run are the result of (de)serialization", () => {
const input = {
str: "",
Expand Down Expand Up @@ -429,17 +433,33 @@ describe("ai", () => {
// @ts-expect-error Invalid data
// eslint-disable-next-line @typescript-eslint/no-unused-vars
void step.ai.wrap("", (flag: boolean, value: number) => {});

// @ts-expect-error Invalid data
// eslint-disable-next-line @typescript-eslint/no-unused-vars
void step.ai.wrap("", function (flag: boolean, value: number) {});
});

test("disallow step inputs when function does not expect them", () => {
// @ts-expect-error Invalid data
void step.ai.wrap("", () => {}, true);

// @ts-expect-error Invalid data
void step.ai.wrap("", function () {}, true);
});

test("disallow step inputs that don't match what function expects", () => {
// @ts-expect-error Invalid data
// eslint-disable-next-line @typescript-eslint/no-unused-vars
void step.ai.wrap("", (flag: boolean, value: number) => {}, 10, true);

void step.ai.wrap(
"",
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function (flag: boolean, value: number) {},
// @ts-expect-error Invalid data
10,
true
);
});

test("optional input", async () => {
Expand All @@ -453,6 +473,17 @@ describe("ai", () => {
true
)
).resolves.toMatchObject({});

await expect(
step.run(
"",
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function (flag: boolean, value?: number) {
// valid - enough arguments given - missing arg is optional
},
true
)
).resolves.toMatchObject({});
});

test("types returned from ai are the result of (de)serialization", () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/inngest/src/components/InngestStepTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ export const createStepTools = <TClient extends Inngest.Any>(
type?: string
) => {
return createTool<
<TFn extends (...args: Parameters<TFn>) => unknown>(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
<TFn extends (...args: any[]) => unknown>(
idOrOptions: StepOptionsOrId,

/**
Expand Down Expand Up @@ -236,6 +237,7 @@ export const createStepTools = <TClient extends Inngest.Any>(
};
},
{
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
fn: (_, fn, ...input) => fn(...input),
}
);
Expand Down
Loading