-
I'm trying to validate a hashmap and created the following schemas based on hapijs/joi#1294 (comment): export const PersonSchema = Joi.object()
.keys({ name: Joi.string() })
.meta({ className: 'Person' });
export const PersonsSchema = Joi.object()
.pattern(/\w/, PersonSchema)
.meta({ className: 'Persons' }); But the generated interfaces look like export interface Person {
name?: string;
}
export interface Persons {
} instead of export interface Person {
name?: string;
}
export interface Persons {
[x: string]: Person;
} What am I doing wrong? I played around a bit and with export const PersonsSchema = Joi.object()
.unknown()
.pattern(/\w/, PersonSchema)
.meta({ className: 'Persons' }); I get export interface Person {
name?: string;
}
export interface Persons {
/**
* Unknown Property
*/
[x: string]: unknown;
} |
Beta Was this translation helpful? Give feedback.
Answered by
mrjono1
Nov 3, 2021
Replies: 1 comment 1 reply
-
Hey, currently support hasn't been added for export const WalletSchema = Joi.object({
usd: Joi.number().required(),
eur: Joi.number().required()
})
.unknown()
.meta({ className: 'Wallet', unknownType: 'number' }); I think if you add the export const PersonsSchema = Joi.object()
.unknown()
.pattern(/\w/, PersonSchema)
.meta({ className: 'Persons', unknownType: 'Person' }); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
JanMalch
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, currently support hasn't been added for
.pattern()
but I received a PR recently that should solve this issueThis block is from the readme.md
I think if you add the
unknownType
property to.meta()
that should fix the issue with your second attempt like this