-
Notifications
You must be signed in to change notification settings - Fork 55
Conversation
What
This PR adds a new option --link-type LinkTypeName.
When specified, all link types emitted by the full type renderer will be wrapped in the given TypeScript type name.
It's up to the user to somehow add the given type name to the emitted code files.
Here's an example of one of our entity types, generated with --link-type=MaybeLink.
Why
At Notion, we have an annoying problem with content editors and/or automated translations systems deleting content. This leaves behind broken link references which unfortunately are generated as non-nullable by the current system.
To fix, we could add an option to always treat links as IFoo | undefined, but that's not a satisfying answer for us either -- we do want to send some kind of alert or error report whenever our code reads a link that should exist, but doesn't. If we mark everything as ... | undefined, it's really hard to remember to alert about the issue, and easy to paper over with thingy?.nullableLink?.property.
We want to do something more complicated, but it's going to be very Notion-specific. Rather than encoding a specific solution into this tool, we're going to inject a custom type name around all these links. Then, we'll prepend a type import to the generated file in our generator script, which we'll be able to adjust freely without needing any further changes to the tool.