TCMiranda / joi-extract-type

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

Arrays always interpreted as optional when inside an object #12

Closed gustavopch closed 6 years ago

gustavopch commented 6 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
// }