Skip to content

Commit

Permalink
Add a IsClass type check to the StructSchema type
Browse files Browse the repository at this point in the history
  • Loading branch information
Danofu authored Jan 25, 2024
1 parent c88b111 commit e296653
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,13 @@ export type IsRecord<T> = T extends object
? T
: never
: never

/**
* Check if a type is a class type.
*/

export type IsClass<T> = T extends { new(...args: any[]): any } ? T : never;

Check failure on line 259 in src/utils.ts

View workflow job for this annotation

GitHub Actions / ci (14.x)

Replace `(...args:·any[]):·any·}·?·T·:·never;` with `·(...args:·any[]):·any·}·?·T·:·never`

Check failure on line 259 in src/utils.ts

View workflow job for this annotation

GitHub Actions / ci (16.x)

Replace `(...args:·any[]):·any·}·?·T·:·never;` with `·(...args:·any[]):·any·}·?·T·:·never`

Check failure on line 259 in src/utils.ts

View workflow job for this annotation

GitHub Actions / ci (18.x)

Replace `(...args:·any[]):·any·}·?·T·:·never;` with `·(...args:·any[]):·any·}·?·T·:·never`

Check failure on line 259 in src/utils.ts

View workflow job for this annotation

GitHub Actions / ci (14.x)

Replace `(...args:·any[]):·any·}·?·T·:·never;` with `·(...args:·any[]):·any·}·?·T·:·never`

Check failure on line 259 in src/utils.ts

View workflow job for this annotation

GitHub Actions / ci (16.x)

Replace `(...args:·any[]):·any·}·?·T·:·never;` with `·(...args:·any[]):·any·}·?·T·:·never`

Check failure on line 259 in src/utils.ts

View workflow job for this annotation

GitHub Actions / ci (18.x)

Replace `(...args:·any[]):·any·}·?·T·:·never;` with `·(...args:·any[]):·any·}·?·T·:·never`

/**
* Check if a type is a tuple.
*/
Expand Down Expand Up @@ -374,7 +381,9 @@ export type StructSchema<T> = [T] extends [string | undefined | null]
? null
: Struct<E>
: T extends object
? T extends IsRecord<T>
? T extends IsClass<T>
? null
: T extends IsRecord<T>

Check failure on line 386 in src/utils.ts

View workflow job for this annotation

GitHub Actions / ci (14.x)

Insert `··`

Check failure on line 386 in src/utils.ts

View workflow job for this annotation

GitHub Actions / ci (16.x)

Insert `··`

Check failure on line 386 in src/utils.ts

View workflow job for this annotation

GitHub Actions / ci (18.x)

Insert `··`

Check failure on line 386 in src/utils.ts

View workflow job for this annotation

GitHub Actions / ci (14.x)

Insert `··`

Check failure on line 386 in src/utils.ts

View workflow job for this annotation

GitHub Actions / ci (16.x)

Insert `··`

Check failure on line 386 in src/utils.ts

View workflow job for this annotation

GitHub Actions / ci (18.x)

Insert `··`
? null
: { [K in keyof T]: Describe<T[K]> }
: null
Expand Down

0 comments on commit e296653

Please sign in to comment.