Skip to content

Commit 5cf6eba

Browse files
committed
fix: some schema tuning
1 parent 7414927 commit 5cf6eba

2 files changed

Lines changed: 14 additions & 7 deletions

File tree

src/common/schema/schema.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { Infer } from './schema'
22
import type { Expect, IsEqual } from './test'
33
import { cloneJsonObject } from '../data'
4-
import { array, boolean, float, int, literal, number, object, string, stringLiterals, tuple, union } from './schema'
4+
import { any, array, boolean, float, int, literal, number, object, string, stringLiterals, tuple, union } from './schema'
55

66
describe('schema', () => {
77
it('create schema', async () => {
@@ -29,6 +29,7 @@ describe('schema', () => {
2929
age: int().optional(),
3030
active: boolean(),
3131
tags: array(string()).optional(),
32+
info: any(),
3233
// status: stringLiterals(['active', 'trialing', 'past_due', 'paused', 'deleted']),
3334
// status: string<Status>(),
3435
obj: object({
@@ -45,6 +46,7 @@ describe('schema', () => {
4546
test: number
4647
} | undefined
4748
name: string
49+
info?: any
4850
active: boolean
4951
tags?: string[]
5052
lit: 'active' | 'trialing' | 'past_due' | 'paused' | 'deleted'
@@ -73,6 +75,9 @@ describe('schema', () => {
7375
"_default": "123",
7476
"type": "string",
7577
},
78+
"info": Object {
79+
"type": "any",
80+
},
7681
"lit": Object {
7782
"type": "string",
7883
},

src/common/schema/schema.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,15 @@ export function string() {
104104
return new TypeStringClass<string>('string', isString)
105105
}
106106

107-
// export function string() {
108-
// return generic<string>('string', {
109-
// _check: isString,
110-
// })
111-
// }
112-
113107
export function number() {
114108
return generic<number>('number', {
115109
_check: isNumber,
116110
})
117111
}
118112

119113
export const float = number
114+
export const double = number
115+
export const real = number
120116

121117
export function int() {
122118
return generic<number>('int', {
@@ -137,6 +133,12 @@ export function none() {
137133
})
138134
}
139135

136+
export function any() {
137+
return generic<any>('any', {
138+
_check: v => v != null,
139+
})
140+
}
141+
140142
// Object
141143

142144
type ObjectFixOptional<T> = {

0 commit comments

Comments
 (0)