-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Closed
Copy link
Labels
Milestone
Description
Support plan
- is this issue currently blocking your project? (yes/no): no
- is this issue affecting a production system? (yes/no): no
Context
- node version: 14.14
- module version with issue: 17.1.1
- last module version without issue: ?
- environment (e.g. node, browser, native): node
- used with (e.g. hapi application, another framework, standalone, ...): Express
- any other relevant information:
What are you trying to achieve or the steps to reproduce?
When I'm using the any.when() function with the shortcut for switch case:
From (https://joi.dev/api/?v=17.3.0#anywhencondition-options):
const schema = Joi.object({
a: Joi.number().required(),
b: Joi.number()
.when('a', [
{ is: 0, then: 1 },
{ is: 1, then: 2 },
{ is: 2, then: 3, otherwise: 4 }
])
});What was the result you got?
tsc throw me an error saying that the second param options any.when cannot be an [].
Overload 1 of 2, '(ref: string | Reference, options: WhenOptions): AlternativesSchema', gave the following error.
Type '({ is: myKey; then: StringSchema; } | { is: myKey; then: StringSchema; otherwise: Schema; })[]' has no properties in common with type 'WhenOptions'.
Overload 2 of 2, '(ref: Schema, options: WhenSchemaOptions): AlternativesSchema', gave the following error.
Argument of type 'string' is not assignable to parameter of type 'Schema'.
What result did you expect?
Can transpile from TS to JS without any error.
I think I spoted the problem in the index.d.ts:
https://github.com/sideway/joi/blob/master/lib/index.d.ts#L1161
Or
https://github.com/sideway/joi/blob/master/lib/index.d.ts#L2184
Reactions are currently unavailable