Skip to content

Commit

Permalink
fix(vae): Nullable 应包含 null
Browse files Browse the repository at this point in the history
  • Loading branch information
fjc0k committed Oct 10, 2023
1 parent 9215f84 commit 6c95644
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 22 deletions.
3 changes: 2 additions & 1 deletion src/vae/VaeArraySchema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Nullable } from '../types'
import { isArray } from '../utils'
import { VaeLocale, VaeLocaleMessage } from './VaeLocale'
import { VaeSchema, VaeSchemaOf } from './VaeSchema'
Expand All @@ -7,7 +8,7 @@ export type VaeArraySchemaElementOf<T> = T extends Array<infer X>
: never

export class VaeArraySchema<
T0 extends any[] | undefined = any[],
T0 extends Nullable<any[]> = any[],
T extends NonNullable<T0> = NonNullable<T0>,
> extends VaeSchema<T0> {
constructor(
Expand Down
3 changes: 2 additions & 1 deletion src/vae/VaeBooleanSchema.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Nullable } from '../types'
import { isBoolean } from '../utils'
import { VaeLocale, VaeLocaleMessage } from './VaeLocale'
import { VaeSchema } from './VaeSchema'

export class VaeBooleanSchema<
T0 extends boolean | undefined = boolean,
T0 extends Nullable<boolean> = boolean,
> extends VaeSchema<T0> {
constructor(message: VaeLocaleMessage = VaeLocale.boolean.type) {
super({
Expand Down
3 changes: 2 additions & 1 deletion src/vae/VaeDateSchema.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { anyToDate, isDate, isValid } from '../date'
import { Nullable } from '../types'
import { VaeLocale, VaeLocaleMessage } from './VaeLocale'
import { VaeSchema } from './VaeSchema'

export class VaeDateSchema<
T0 extends Date | undefined = Date,
T0 extends Nullable<Date> = Date,
> extends VaeSchema<T0> {
constructor(message: VaeLocaleMessage = VaeLocale.date.type) {
super({
Expand Down
3 changes: 2 additions & 1 deletion src/vae/VaeNumberSchema.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Nullable } from '../types'
import { isInteger, isNumeric, toNumber } from '../utils'
import { VaeLocale, VaeLocaleMessage } from './VaeLocale'
import { VaeSchema } from './VaeSchema'

export class VaeNumberSchema<
T0 extends number | undefined = number,
T0 extends Nullable<number> = number,
> extends VaeSchema<T0> {
constructor(message: VaeLocaleMessage = VaeLocale.number.type) {
super({
Expand Down
4 changes: 2 additions & 2 deletions src/vae/VaeObjectSchema.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PartialBy, RequiredBy } from '../types'
import { Nullable, PartialBy, RequiredBy } from '../types'
import { difference, intersection, isPlainObject, startsWith } from '../utils'
import { VaeLocale, VaeLocaleMessage } from './VaeLocale'
import { VaeSchema, VaeSchemaOf } from './VaeSchema'
Expand All @@ -8,7 +8,7 @@ export type VaeObjectSchemaShapeOf<T> = {
}

export class VaeObjectSchema<
T0 extends Record<any, any> | undefined = Record<any, any>,
T0 extends Nullable<Record<any, any>> = Record<any, any>,
T extends NonNullable<T0> = NonNullable<T0>,
> extends VaeSchema<T0> {
constructor(
Expand Down
3 changes: 2 additions & 1 deletion src/vae/VaeStringSchema.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Nullable } from '../types'
import {
endsWith,
includes,
Expand All @@ -12,7 +13,7 @@ import { VaeLocale, VaeLocaleMessage } from './VaeLocale'
import { VaeSchema } from './VaeSchema'

export class VaeStringSchema<
T0 extends string | undefined = string,
T0 extends Nullable<string> = string,
> extends VaeSchema<T0> {
constructor(message: VaeLocaleMessage = VaeLocale.string.type) {
super({
Expand Down
30 changes: 15 additions & 15 deletions src/vae/vae.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IsAny } from '../types'
import { IsAny, Nullable } from '../types'
import { VaeArraySchema, VaeArraySchemaElementOf } from './VaeArraySchema'
import { VaeBooleanSchema } from './VaeBooleanSchema'
import { VaeDateSchema } from './VaeDateSchema'
Expand All @@ -13,11 +13,11 @@ import { VaeObjectSchema, VaeObjectSchemaShapeOf } from './VaeObjectSchema'
import { VaeSchema } from './VaeSchema'
import { VaeStringSchema } from './VaeStringSchema'

function string<T extends string | undefined = string>(
function string<T extends Nullable<string> = string>(
schema: (schema: VaeStringSchema<T>) => VaeStringSchema<T>,
message?: VaeLocaleMessage,
): VaeStringSchema<T>
function string<T extends string | undefined = string>(
function string<T extends Nullable<string> = string>(
message?: VaeLocaleMessage,
): VaeStringSchema<T>
function string(messageOrSchema: any, message?: any) {
Expand All @@ -26,11 +26,11 @@ function string(messageOrSchema: any, message?: any) {
: new VaeStringSchema(messageOrSchema)
}

function number<T extends number | undefined = number>(
function number<T extends Nullable<number> = number>(
schema: (schema: VaeNumberSchema<T>) => VaeNumberSchema<T>,
message?: VaeLocaleMessage,
): VaeNumberSchema<T>
function number<T extends number | undefined = number>(
function number<T extends Nullable<number> = number>(
message?: VaeLocaleMessage,
): VaeNumberSchema<T>
function number(messageOrSchema: any, message?: any) {
Expand All @@ -39,11 +39,11 @@ function number(messageOrSchema: any, message?: any) {
: new VaeNumberSchema(messageOrSchema)
}

function date<T extends Date | undefined = Date>(
function date<T extends Nullable<Date> = Date>(
schema: (schema: VaeDateSchema<T>) => VaeDateSchema<T>,
message?: VaeLocaleMessage,
): VaeDateSchema<T>
function date<T extends Date | undefined = Date>(
function date<T extends Nullable<Date> = Date>(
message?: VaeLocaleMessage,
): VaeDateSchema<T>
function date(messageOrSchema: any, message?: any) {
Expand All @@ -52,11 +52,11 @@ function date(messageOrSchema: any, message?: any) {
: new VaeDateSchema(messageOrSchema)
}

function boolean<T extends boolean | undefined = boolean>(
function boolean<T extends Nullable<boolean> = boolean>(
schema: (schema: VaeBooleanSchema<T>) => VaeBooleanSchema<T>,
message?: VaeLocaleMessage,
): VaeBooleanSchema<T>
function boolean<T extends boolean | undefined = boolean>(
function boolean<T extends Nullable<boolean> = boolean>(
message?: VaeLocaleMessage,
): VaeBooleanSchema<T>
function boolean(messageOrSchema: any, message?: any) {
Expand All @@ -66,17 +66,17 @@ function boolean(messageOrSchema: any, message?: any) {
}

function object<
T0 extends Record<any, any> | undefined = Record<any, any>,
T0 extends Record<any, Nullable<any>> = Record<any, any>,
T extends NonNullable<T0> = NonNullable<T0>,
>(
shape: VaeObjectSchemaShapeOf<T>,
message?: VaeLocaleMessage,
): VaeObjectSchema<IsAny<keyof T0> extends true ? T : T0>
function object<T extends Record<any, any> | undefined = Record<any, any>>(
function object<T extends Nullable<Record<any, any>> = Record<any, any>>(
schema: (schema: VaeObjectSchema<T>) => VaeObjectSchema<T>,
message?: VaeLocaleMessage,
): VaeObjectSchema<T>
function object<T extends Record<any, any> | undefined = Record<any, any>>(
function object<T extends Nullable<Record<any, any>> = Record<any, any>>(
message?: VaeLocaleMessage,
): VaeObjectSchema<T>
function object(messageOrSchemaOrShape: any, message?: any) {
Expand All @@ -87,15 +87,15 @@ function object(messageOrSchemaOrShape: any, message?: any) {
: new VaeObjectSchema(undefined, messageOrSchemaOrShape)
}

function array<T extends unknown[] | undefined = unknown[]>(
function array<T extends Nullable<unknown[]> = unknown[]>(
element: VaeArraySchemaElementOf<T>,
message?: VaeLocaleMessage,
): VaeArraySchema<T>
function array<T extends unknown[] | undefined = unknown[]>(
function array<T extends Nullable<unknown[]> = unknown[]>(
schema: (schema: VaeArraySchema<T>) => VaeArraySchema<T>,
message?: VaeLocaleMessage,
): VaeArraySchema<T>
function array<T extends unknown[] | undefined = unknown[]>(
function array<T extends Nullable<unknown[]> = unknown[]>(
message?: VaeLocaleMessage,
): VaeArraySchema<T>
function array(messageOrSchemaOrElement: any, message?: any) {
Expand Down

0 comments on commit 6c95644

Please sign in to comment.