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

[BUG] 3.15.3 breaks union types returned from step.run #513

Closed
gwax opened this issue Mar 6, 2024 · 5 comments · Fixed by #512
Closed

[BUG] 3.15.3 breaks union types returned from step.run #513

gwax opened this issue Mar 6, 2024 · 5 comments · Fixed by #512
Assignees
Labels
Bug Something isn't working 📦 inngest Affects the `inngest` package

Comments

@gwax
Copy link

gwax commented Mar 6, 2024

Describe the bug
Since 3.15.3, step.run with union return types are being given return type of Promise<any>

To Reproduce
Steps to reproduce the behavior:

  1. Create file with:
import { EventSchemas, Inngest } from "inngest";

type Thing = {
  data: {
    stuff?: string | null;
  };
};

type Events = {
  "thing/thing": Thing;
};

const inngest = new Inngest({
  id: "inngest",
  schemas: new EventSchemas().fromRecord<Events>(),
});

function logstuff(stuff: string | null) {
  console.log(stuff);
}

export default inngest.createFunction(
  {
    id: "thing-thing",
  },
  { event: "thing/thing" },
  async ({ step, event }) => {
    let { stuff } = event.data;
    stuff = await step.run("fix-undefined-stuff", () => {  // <- this is typed as (...) => Promise<any> should be (...) => Promise<string | null>
      let newStuff = stuff;
      if (newStuff === undefined) {
        newStuff = null;
      }
      return newStuff;  // <- type = string | null
    });

    await step.run("log-stuff", () => {
      logstuff(stuff);  // <-- This line is fine on 3.15.2 but type errors on 3.15.3
    });
  },
);
  1. Typecheck with inngest==3.15.2 -> no errors
  2. Typeschek with inngest==3.15.3 -> type is not narrowed by running "fix-undefined-stuff" step

Expected behavior
No type errors

Code snippets / Logs / Screenshots

[{
	"resource": ".../thing.ts",
	"owner": "typescript",
	"code": "2345",
	"severity": 8,
	"message": "Argument of type 'string | null | undefined' is not assignable to parameter of type 'string | null'.\n  Type 'undefined' is not assignable to type 'string | null'.",
	"source": "ts",
	"startLineNumber": 38,
	"startColumn": 16,
	"endLineNumber": 38,
	"endColumn": 21
}]

System info (please complete the following information):

  • OS: Mac
  • npm package Version 3.15.4

Additional context
Add any other context about the problem here.

Copy link

linear bot commented Mar 6, 2024

@gwax gwax changed the title [BUG] 3.15.4 breaks union types returned from step.run [BUG] 3.15.3 breaks union types returned from step.run Mar 6, 2024
@gwax
Copy link
Author

gwax commented Mar 6, 2024

Updated: the issue started in 3.15.3 NOT 3.15.4

@jpwilliams jpwilliams added Bug Something isn't working 📦 inngest Affects the `inngest` package labels Mar 6, 2024
@jpwilliams jpwilliams self-assigned this Mar 6, 2024
jpwilliams added a commit that referenced this issue Mar 6, 2024
@jpwilliams
Copy link
Member

Thanks for the report, @gwax!

I've added a fix for this at #512. You can test it out now with:

npm install inngest@pr-512

Looks like our supported TS versions have grown wider than unional/type-plus that we've been using for the occasional helper type. The same happened recently with sindresorhus/type-fest in #500.

Let me know if the above works for you and I'll ship this tomorrow to fix.

@jpwilliams
Copy link
Member

The above fix for this is shipped in v3.15.5. 🙂

@gwax
Copy link
Author

gwax commented Mar 8, 2024

I can confirm this is fixed. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working 📦 inngest Affects the `inngest` package
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants