optional < input , const pattern > ( pattern ) : Chainable < OptionalP < input , pattern > , "optional" > Type Parameters input const pattern extends undefined | null | string | number | bigint | boolean | symbol | readonly [ ] | readonly [ unknown , unknown ] | readonly [ unknown , unknown ] | { [k : string ]: unknown ; } | UnknownMatcher | PatternMatcher < input > | { readonly [ k in string | number | symbol ] ?: Pattern < Readonly < MergeUnion < Exclude < input , readonly any [] | Primitives | Map < any , any > | Set < any > > > > [ k ] > } | readonly UnknownPattern [] | readonly [ UnknownPattern , UnknownPattern ] | readonly [ UnknownPattern , UnknownPattern ] Returns Chainable < OptionalP < input , pattern > , "optional" > Defined in node_modules/ts-pattern/dist/patterns.d.ts:75
P.optional(subpattern)
takes a sub pattern and returns a pattern which matches if the key is undefined or if it is defined and the sub pattern matches its value.Read the documentation for
P.optional
on GitHub