-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Labels
typescriptRelated to TypeScript APIRelated to TypeScript APIwontfixThis will not be worked onThis will not be worked on
Description
if I have a union like this on my schema, the type will be a union:
const schema = S.union(["Win", "Draw", "Loss"])
type Schema = S.Output<typeof schema> // "Win" | "Draw" | "Loss"That is correct.
But if the type is optional, nullish, array, etc., the union becomes a simple string:
const schema = S.optional(S.union(["Win", "Draw", "Loss"]))
type Schema = S.Output<typeof schema> // string | undefinedconst schema = S.nullish(S.union(["Win", "Draw", "Loss"]))
type Schema = S.Output<typeof schema> // string | null | undefinedconst schema = S.array(S.union(["Win", "Draw", "Loss"]))
type Schema = S.Output<typeof schema> // string[]The only way I found to not get this behaviour is using S.schema in any strings of my union:
const schema = S.optional(S.union([S.schema("Win"), S.schema("Draw"), S.schema("Loss")]))
type Schema = S.Output<typeof schema> // "Win" | "Draw" | "Loss" | undefinedIs this a bug or it is the intended behaviour? I'm using [email protected].
Metadata
Metadata
Assignees
Labels
typescriptRelated to TypeScript APIRelated to TypeScript APIwontfixThis will not be worked onThis will not be worked on