Skip to content

Can't use discriminatedUnion after transform #2100

Discussion options

You must be logged in to vote

Is this what you are looking for?

const noteSchema = z.object( {
    type: z.literal( 'Note' ),
    id: apId,
    to: recipients,
    cc: recipients,
    content: z.string(),
    attachment: z.array( attachmentSchema ).optional().catch( undefined ),
    inReplyTo: apId.optional(),
    attributedTo: apId,
    published: published(),
    quoteUrl: apId.optional(),
} )

const flexibleNoteSchema = noteSchema.extend( {
    quoteURL: apId.optional(),
    quoteUri: apId.optional(),
    _misskey_quote: apId.optional(),
} ).transform( ( note ) => {
    const { quoteUrl, quoteUri, quoteURL, _misskey_quote, ...rest } = note
    return {
        quoteUrl: quoteUrl || quoteUri || quoteURL || _misskey_…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@alexgleason
Comment options

@alexgleason
Comment options

@JacobWeisenburger
Comment options

Answer selected by alexgleason
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants