Skip to content

Commit e0b0534

Browse files
committed
🔧 fix: #1597 parse, safeParse
1 parent 80bb84d commit e0b0534

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/schema.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import type {
2727
InputSchema,
2828
MaybeArray,
2929
StandaloneInputSchema,
30-
StandardSchemaV1LikeValidate
30+
StandardSchemaV1LikeValidate,
31+
UnwrapSchema
3132
} from './types'
3233

3334
import type { StandardSchemaV1Like } from './types'
@@ -40,10 +41,10 @@ export interface ElysiaTypeCheck<T extends TSchema>
4041
provider: 'typebox' | 'standard'
4142
schema: T
4243
config: Object
43-
Clean?(v: unknown): T
44-
parse(v: unknown): T
44+
Clean?(v: unknown): UnwrapSchema<T>
45+
parse(v: unknown): UnwrapSchema<T>
4546
safeParse(v: unknown):
46-
| { success: true; data: T; error: null }
47+
| { success: true; data: UnwrapSchema<T>; error: null }
4748
| {
4849
success: false
4950
data: null

test/types/utils.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { t, getSchemaValidator } from '../../src'
2+
import { expectTypeOf } from 'expect-type'
3+
4+
// schema validator
5+
{
6+
const schema = t.Object({
7+
id: t.Number(),
8+
name: t.String()
9+
})
10+
11+
const validator = getSchemaValidator(schema)
12+
const result = validator.safeParse({ id: 1, name: 'test' })
13+
14+
if (result.success) {
15+
expectTypeOf(result.data).toEqualTypeOf<{ id: number; name: string }>()
16+
}
17+
}

0 commit comments

Comments
 (0)