UNPKG
lean4-code-actions
Version:
latest (1.1.32)
1.1.32
Refactorings and snippets for Lean 4
lean4-code-actions
/
libs
/
utils
/
zod
/
getDiscriminatedUnionSchema.ts
5 lines
(3 loc)
•
283 B
text/typescript
View Raw
1
2
3
4
5
import
{ z }
from
'zod'
import
{
AnyZodObject
}
from
'zod/lib/types'
export
const
getDiscriminatedUnionSchema = <
Key
extends
string
,
Value
extends
string
>
(
key
:
Key
,
value
:
Value
) =>
<
Schema
extends
AnyZodObject
>
(
schema
:
Schema
) =>
z.
object
({
type
: z.
literal
(value) }).
merge
(schema)