Skip to content

Commit

Permalink
fix(yup): 类型优化
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Mar 3, 2021
1 parent 8fa4967 commit 9d145bf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
15 changes: 15 additions & 0 deletions src/validator/yup.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { enUS } from './locale/enUS'
import { expectType } from '../dev'
import { run } from '../utils'
import { yup } from './yup'
import { zhCN } from './locale/zhCN'
Expand Down Expand Up @@ -161,4 +162,18 @@ describe('yup', () => {
}),
).toMatchSnapshot()
})

test('布尔、enum类型正常', () => {
type X = yup.GetObjectSchema<{
disabled: boolean
gender: 'male' | 'female'
}>
expectType<
X,
{
disabled: yup.BooleanSchema<boolean>
gender: yup.StringSchema<string>
}
>()
})
})
6 changes: 3 additions & 3 deletions src/validator/yupTypes/mixed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ declare module 'yup/es' {
}

export type GetSchema<T> = T extends string
? StringSchema<T>
? StringSchema<string>
: T extends number
? NumberSchema<T>
? NumberSchema<number>
: T extends boolean
? BooleanSchema<T>
? BooleanSchema<boolean>
: T extends Array<infer X>
? ArraySchema<X>
: T extends {}
Expand Down

0 comments on commit 9d145bf

Please sign in to comment.