Skip to content

Issue with generics #351

Answered by sinclairzx81
kostysh asked this question in Q&A
Mar 24, 2023 · 3 comments · 2 replies
Discussion options

You must be logged in to vote

@kostysh Hi.

Instantiation Expressions mixed with TypeBox types can be quite tricky to get right, but the following should implement something close to what you're trying to achieve.

TypeScript Link Here

import { Type, Static, TSchema } from '@sinclair/typebox'

// ----------------------------------------------------------------------
// Generic Query Options
// ----------------------------------------------------------------------

export type  Options<T extends TSchema> = Static<ReturnType<typeof Options<T>>>
export const Options = <T extends TSchema>(query: T) => Type.Composite([
  Type.Object({ id: Type.String() }),
  Type.Object({
    querySchema: Type.Any(),
    query
  })
])

// --…

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@kostysh
Comment options

Answer selected by kostysh
Comment options

You must be logged in to vote
1 reply
@kostysh
Comment options

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
2 participants