Skip to content
Discussion options

You must be logged in to vote

@carcigenicate Hi,

Is it possible to achieve something similar that will allow for string suggestions while allowing all strings, and pass both TS and schema validation?

Probably the easiest way to achieve this is to use the Unsafe type to override type inference.

Docs: https://sinclairzx81.github.io/typebox/#/docs/type/unsafe

Ref: Example

import Type, { type Static } from 'typebox'

// this type will validate for all strings, but infer with the ... | (string & {})
const T = Type.Unsafe<'a' | 'b' | 'c' | 'd' | (string & {})>(Type.String())

type T = Static<typeof T>

This type will validate for all strings, but will auto complete for the known variants (and allow additional via (string &…

Replies: 1 comment 1 reply

Comment options

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

Answer selected by carcigenicate
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