Skip to content

Conversation

@jsantell
Copy link
Collaborator

@jsantell jsantell commented Apr 24, 2025

  • Gmail recipe was using as JSONSchema rather than satisfies JSONSchema, which was causing some type issues
  • No strong feelings for naming between Writable, Mutable, mostly noting distinction
  • Pulled in extra satisfies JSONSchema clauses from @ubik2 Change some places where we declared a schema "as JSONSchema" #1103 (without which Schema resolves to any)
  • The Writable type helper was not applying mutability recursively; an object with a string type would break out its properties, starting with:
// via `Schema<typeof EmailSchema>`
type Email = {
    readonly id: string;
} & {} & Record<...>

but typed as

// via `Writable<Schema<typeof EmailSchema>>`
type EmailWritable = {
    id: Writable<{
        toString: () => string;
        charAt: (pos: number) => string;
        charCodeAt: (index: number) => number;
        concat: (...strings: string[]) => string;
        indexOf: (searchString: string, position?: number) => number;
        ... 46 more ...;
        [Symbol.iterator]: () => StringIterator<string>;
    }>;
}

With using a recursive version of the Mutable helper, the types now resolve to a query instance:

// via `Mutable<Schema<typeof EmailSchema>>`
type Email  = {
    id: string;
}

While the email case is mostly readonly, and this is used as just an illustrative example (bgAdmin for example does need mutability), we do set ID on a email query, a property of JSONSchema, not Schema; this is failing types currently, not sure of the way forward here:

email[ID] = email.id

@jsantell
Copy link
Collaborator Author

While the email case is mostly readonly, and this is used as just an illustrative example (bgAdmin for example does need mutability), we do set ID on a email query, a property of JSONSchema, not Schema; this is failing types currently, not sure of the way forward here:

email[ID] = email.id

Ah, maybe #1033 will fix?

@jsantell
Copy link
Collaborator Author

This fixes up the schema types in recipes successfully 👍

Copy link
Contributor

@ubik2 ubik2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@jsantell jsantell merged commit ad4b646 into main Apr 24, 2025
5 checks passed
@jsantell jsantell deleted the schema-types branch April 24, 2025 17:47
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.

3 participants