Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --link-type option #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

justjake
Copy link

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.

image

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant