hjkcai / typesafe-joi

A fork of joi that produces typed validation results in TypeScript
MIT License
73 stars 9 forks source link

Joi.extend base won't compile #14

Closed typeofweb closed 5 years ago

typeofweb commented 5 years ago

Code to reproduce:

const x = Joi.extend({
  base: Joi.array(),
})

fails with the following error:

Argument of type '{ base: ArraySchema<Value<any[], never, never, undefined, never>>; }' is not assignable to parameter of type 'Extension | Extension[]'.
  Property 'name' is missing in type '{ base: ArraySchema<Value<any[], never, never, undefined, never>>; }' but required in type 'Extension'. ts(2345)

This is likely because extends is defined with the use of JoiLib.Extension which points to the original @types/hapi__joi typings, and Joi.array defined there is not compatible with the one from typesafe-joi.

hjkcai commented 5 years ago

This error was because you forgot name option in the Extension type. However, the Extension itself should be adapted to typesafe-joi.

Fixed in 2.0.2.

typeofweb commented 5 years ago

Oh, my full code did have name, I accidentally must've deleted it and pasted the wrong error 🤦‍♂ Sorry about that. Thanks for the quick fix! 👍