feat: 🏷️ add utility types

This commit is contained in:
Julien Oculi 2024-05-07 11:32:05 +02:00
parent 9db06a607b
commit b0d9942586

28
types.ts Normal file
View 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
}