TCMiranda / joi-extract-type

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

Arrays always interpreted as optional when inside an object #12

Closed gustavopch closed 5 years ago

gustavopch commented 5 years ago

As the title says, Joi.array() is always thought to be optional when inside an object.

import * as Joi from 'joi'
import 'joi-extract-type'

const schema = Joi.object({
  channels: Joi.array().items(Joi.string()).required()
})

type Schema = Joi.extractType<typeof schema>

// Result:
// type Schema = {
//   channels?: string[] | undefined
// }