TCMiranda / joi-extract-type

Provides native type extraction from Joi schemas for Typescript
MIT License
151 stars 27 forks source link

Is it possible to infer nullable type? #21

Closed ildukm closed 4 years ago

ildukm commented 4 years ago

Hello, thank you for your project. I was wondering if it's possible to infer nullable type.

const n = Joi.number().required().allow(null);
Joi.extractType<typeof n>; // expect number | null
TCMiranda commented 4 years ago

Yes it is, actually .allow needs to be implemented for every schema. It is not difficult, I just didn't have time to do it. Help is welcome :grin:

See https://github.com/TCMiranda/joi-extract-type/issues/5