feat: 🏷️ add utility types
This commit is contained in:
parent
9db06a607b
commit
b0d9942586
28
types.ts
Normal file
28
types.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import { JsonValue } from '@std/json'
|
||||
|
||||
export type UUID = `${string}-${string}-${string}-${string}-${string}`
|
||||
export type DateString =
|
||||
`${number}-${number}-${number}T${number}:${number}:${number}.${number}Z"`
|
||||
export type Login = `${string}.${string}`
|
||||
export type MailAddress = `${string}@${string}.${string}`
|
||||
|
||||
export type ToJson<T> = T extends JsonValue ? T
|
||||
: T extends { toJSON(): unknown } ? ReturnType<T['toJSON']>
|
||||
: T extends { toJSON(): unknown }[]
|
||||
? { [K: number]: ReturnType<T[typeof K]['toJSON']> }
|
||||
: never
|
||||
|
||||
export type MethodOf<T, K extends keyof T> = {
|
||||
[P in keyof Pick<T, T[K] extends CallableFunction ? K : never>]: never
|
||||
}
|
||||
|
||||
export type Serializable<T extends object> = {
|
||||
[key in Exclude<keyof T, 'toJSON' | 'toString' | 'toPrimitive' | 'valueOf'>]:
|
||||
ToJson<T[key]>
|
||||
}
|
||||
|
||||
export type Posix = {
|
||||
id: number
|
||||
home: string
|
||||
shell: string
|
||||
}
|
Loading…
Reference in a new issue