Simplification of Inngest Event Definitions #687
khill-fbmc
started this conversation in
Show and tell
Replies: 1 comment 2 replies
-
Wow, that looks awesome! I hadn't really even considered the possibilities of creating "higher-order types" manually. As long as whatever variables you're using are inferred as narrowed strings/objects, you could totally abstract this out to something like: const data = type({
mailTo: "string",
subject: "string",
message: "string"
})
const defineEvent = <name extends string>(name: name) =>
({
name: `'${name}'`,
data
} as const)
const emailSend = type(defineEvent("app/email.send"))
// Inferred as:
//
// Type<{
// name: "app/email.send";
// data: {
// mailTo: string;
// subject: string;
// message: string;
// };
// }> Unfortunately, TS does not seem to want to cooperate with narrowing dynamic key syntax like Really nice to see it being applied so creatively so early on. Great work! 🔥 |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello 👋🏻
I wanted to stop by and sing a little praise on how your library solved a problem for me.
Background
I am using Inngest, an event framework, and you can see in this small example that the event string is repeated 3 times!
I don't like that at all.
My Solution
I tried making my own utility type that could help with the name...
That worked fine, defining the event like so:
which enabled me to export the type to the module with the client and merge them all together. I still don't like that I can't really use the type at all, it just type hints the params for me, which is nice, but I wanted more...
Enter ArkType
With your beautiful library I was able to replicate the type, and de-duplicate the event name into one variable!
YES!
Beta Was this translation helpful? Give feedback.
All reactions