Skip to content

Define a single schema with end-to-end Type safety #211

Answered by airtonix
airtonix asked this question in Q&A
Discussion options

You must be logged in to vote

So i started picking apart the types behind the read api and it looks like we need this type exposed:

type ValueForReadingWithMode<
    Schema extends ComponentSchema,
    ResolveLinkedFiles extends boolean | undefined
> = ResolveLinkedFiles extends true
    ? ValueForReadingDeep<Schema>
    : ValueForReading<Schema>;

type ResolvedSchema<Schema extends Record<string, ComponentSchema>, SlugField = void> = {
    [Key in keyof Schema]: SlugField extends Key
        ? Schema[Key] extends SlugFormField<any, any, any, infer SlugSerializedValue>
            ? SlugSerializedValue
            : ValueForReadingWithMode<Schema[Key], true>
        : ValueForReadingWithMode<Schema[Key], true>;
}
S…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@airtonix
Comment options

@airtonix
Comment options

@airtonix
Comment options

Answer selected by airtonix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants