maghis / types-joi

TypeScript types for joi (Object schema description language and validator for JavaScript objects) https://github.com/hapijs/joi
28 stars 4 forks source link

Fixes incorrect type narrowing of nullable string #6

Closed lee-hyunkyu closed 2 years ago

lee-hyunkyu commented 2 years ago

When creating a Joi schema with modifiers .allow(null).required(), the type of the resulting object is not correctly nullable even if it passes the runtime check

const schema = joi.object({
   x: joi.string().allow(null).required()
})

const result = joi.attempt({ x: null }, schema)
// expected: typeof result = { x: string | null } 

Current Behavior current (incorrect) behavior

Expected Behavior expected