Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Summary <!-- Succinctly describe your change, providing context, what you've changed, and why. --> `Jsonify` is used to represent a step output going through serialization as it passes to and from an Inngest Server in JSON. This used to be part of the `type-fest` package, but we removed that when introducing support for TypeScript 5.4 in #500, as our version support range for TS exceeded what was provided by the `type-fest` package. As part of that, we've pulled `Jsonify` into our code. There are some issues (in the related section) we can now fix much more easily. The issue that motivated this change (#509) would also have been solved by allowing a developer to provide types that describe how the output of a step is transformed. This is available, but is a rare ask and needs time to implement. ## Checklist <!-- Tick these items off as you progress. --> <!-- If an item isn't applicable, ideally please strikeout the item by wrapping it in "~~"" and suffix it with "N/A My reason for skipping this." --> <!-- e.g. "- [ ] ~~Added tests~~ N/A Only touches docs" --> - [ ] ~Added a [docs PR](https://github.com/inngest/website) that references this PR~ N/A Docs only outline that this is a helper, not specific behaviour - [x] Added unit/integration tests - [x] Added changesets if applicable ## Related <!-- A space for any related links, issues, or PRs. --> <!-- Linear issues are autolinked. --> <!-- e.g. - INN-123 --> <!-- GitHub issues/PRs can be linked using shorthand. --> <!-- e.g. "- inngest/inngest#123" --> <!-- Feel free to remove this section if there are no applicable related links.--> - Fixes #509 (marking this as a fix, but again, note that middleware typing can also solve different strains of this issue) - Fixes #456 - Fixes #513 - Fixes #98
- Loading branch information
1 parent
783e7be
commit 8f03159
Showing
20 changed files
with
292 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"inngest": patch | ||
--- | ||
|
||
Fix union step outputs sometimes being typed as `any` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"inngest": patch | ||
--- | ||
|
||
Fix step output typing (`Jsonify`) removing detail from mapped object types with overrides |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"inngest": patch | ||
--- | ||
|
||
Fix step output typing (`Jsonify`) omitting `unknown` and literals |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { type Jsonify } from "@local/helpers/jsonify"; | ||
import { type IsAny, type IsEqual, type IsUnknown } from "@local/helpers/types"; | ||
import { assertType } from "../test/helpers"; | ||
|
||
describe("Jsonify", () => { | ||
describe("unnested", () => { | ||
test("allows `any`", () => { | ||
type Actual = Jsonify<any>; | ||
assertType<IsAny<Actual>>(true); | ||
}); | ||
|
||
test("allows `unknown`", () => { | ||
type Actual = Jsonify<unknown>; | ||
assertType<IsUnknown<Actual>>(true); | ||
}); | ||
|
||
test("allows number literals", () => { | ||
type Actual = Jsonify<1>; | ||
type Expected = 1; | ||
assertType<IsEqual<Actual, Expected>>(true); | ||
}); | ||
|
||
test("allows string literals", () => { | ||
type Actual = Jsonify<"foo">; | ||
type Expected = "foo"; | ||
assertType<IsEqual<Actual, Expected>>(true); | ||
}); | ||
}); | ||
|
||
describe("nested", () => { | ||
test("allows `any`", () => { | ||
type Actual = Jsonify<{ foo: any }>; | ||
type Expected = { foo: any }; | ||
assertType<IsEqual<Actual, Expected>>(true); | ||
}); | ||
|
||
test("allows `unknown`", () => { | ||
type Actual = Jsonify<{ foo: unknown }>; | ||
type Expected = { foo: unknown }; | ||
assertType<IsEqual<Actual, Expected>>(true); | ||
}); | ||
|
||
test("allows number literals", () => { | ||
type Actual = Jsonify<{ foo: 1 }>; | ||
type Expected = { foo: 1 }; | ||
assertType<IsEqual<Actual, Expected>>(true); | ||
}); | ||
|
||
test("allows string literals", () => { | ||
type Actual = Jsonify<{ foo: "bar" }>; | ||
type Expected = { foo: "bar" }; | ||
assertType<IsEqual<Actual, Expected>>(true); | ||
}); | ||
}); | ||
|
||
describe("#513", () => { | ||
test("appropriately types `string | null` when unnested", () => { | ||
type Actual = Jsonify<string | null>; | ||
type Expected = string | null; | ||
assertType<IsAny<Actual>>(false); | ||
assertType<IsEqual<Actual, Expected>>(true); | ||
}); | ||
|
||
test("appropriately types `string | null` when nested", () => { | ||
type Actual = Jsonify<{ foo: string | null }>; | ||
type Expected = { foo: string | null }; | ||
assertType<IsAny<Actual["foo"]>>(false); | ||
assertType<IsEqual<Actual, Expected>>(true); | ||
}); | ||
}); | ||
|
||
describe("#98", () => { | ||
test("allows mapped types with overrides when unnested", () => { | ||
interface Foo { | ||
[x: string]: any; | ||
foo: boolean; | ||
} | ||
|
||
type Actual = Jsonify<Foo>; | ||
type Expected = { | ||
[x: string]: any; | ||
foo: boolean; | ||
}; | ||
|
||
assertType<IsEqual<Actual, Expected>>(true); | ||
assertType<IsEqual<Actual["foo"], boolean>>(true); | ||
assertType<IsAny<Actual["bar"]>>(true); | ||
}); | ||
|
||
test("allows mapped types with overrides when nested", () => { | ||
interface Foo { | ||
[x: string]: any; | ||
foo: boolean; | ||
} | ||
|
||
type Actual = Jsonify<{ foo: Foo }>; | ||
type Expected = { foo: { [x: string]: any; foo: boolean } }; | ||
|
||
assertType<IsEqual<Actual, Expected>>(true); | ||
assertType<IsEqual<Actual["foo"]["foo"], boolean>>(true); | ||
assertType<IsAny<Actual["foo"]["bar"]>>(true); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.