inngest / inngest-js

The developer platform for easily building reliable workflows with zero infrastructure for TypeScript & JavaScript
https://www.inngest.com/
GNU General Public License v3.0
414 stars 41 forks source link

`strictNullChecks: false` breaks `Jsonify` typing #534

Open jpwilliams opened 5 months ago

jpwilliams commented 5 months ago

Summary

Step returns use the Jsonify type to represent the result of a step being (de)serialized as it is passed to and from Inngest.

If strictNullChecks: false is set in a user's tsconfig.json, however, this type sets some properties to optional that shouldn't be optional.

Example

Here's a playground example with strictNullChecks: false set. Notice how foo is optional where it shouldn't be. https://tsplay.dev/WyVMKw

import { Inngest } from "inngest";

const inngest = new Inngest({ id: "my-app" });

inngest.createFunction(
  { id: "my-fn" },
  { event: "my/event" },
  async ({ step }) => {
    // `foo` should not be optional
    const obj = await step.run("get-obj", () => ({
      //  ^? const obj: { foo?: string; }
      foo: "bar",
    }));
  },
);

Cause

This issue was introduced in #512 and released in 3.15.5. Specifically, this piece here:

https://github.com/inngest/inngest-js/blob/56c7ee2fc8074f9fff378268e542678294dc5c34/packages/inngest/src/helpers/jsonify.ts#L306-L317

Solution

Some TypeScript packages that perform some similar functionality are very opinionated about required configuration options. For example, type-fest: https://github.com/sindresorhus/type-fest/pull/668#issuecomment-1801317701

However, as we wish to fit as quietly into a user's existing codebase as possible, ideally we:

linear[bot] commented 5 months ago

INN-2920 `strictNullChecks: false` breaks `Jsonify` typing