Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 withthingy?.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.