Skip to content

Commit 484197f

Browse files
committed
Add test for nested object in typings
1 parent 4bec868 commit 484197f

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

test/typings.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,36 @@ if (noRequiredFieldsValidator(input)) {
205205
if (typeof input.c !== 'undefined') assertType<string>(input.c)
206206
}
207207

208+
const signupValidator = createValidator({
209+
type: 'object',
210+
properties: {
211+
email: {
212+
type: 'string'
213+
},
214+
paymentInformation: {
215+
type: 'object',
216+
properties: {
217+
plan: { type: 'string' },
218+
token: { type: 'string' }
219+
},
220+
required: [
221+
'plan' as 'plan',
222+
'token' as 'token'
223+
]
224+
}
225+
},
226+
required: [
227+
'paymentInformation'
228+
]
229+
})
230+
231+
if (signupValidator(input)) {
232+
if (typeof input.email !== 'string') assertType<undefined>(input.email)
233+
if (typeof input.email !== 'undefined') assertType<string>(input.email)
234+
assertType<string>(input.paymentInformation.plan)
235+
assertType<string>(input.paymentInformation.token)
236+
}
237+
208238
const animalValidator = createValidator({
209239
oneOf: [
210240
{

0 commit comments

Comments
 (0)