2022-11-06 13:50:39 +01:00
|
|
|
type Types = 'string' | 'number' | 'boolean' | 'object'
|
2022-11-07 22:31:17 +01:00
|
|
|
interface TypeMap {
|
2022-11-06 13:50:39 +01:00
|
|
|
string: string
|
|
|
|
number: number
|
|
|
|
boolean: boolean
|
|
|
|
object: object
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isType<T extends Types>(type: T): (v: unknown) => v is TypeMap[T] {
|
|
|
|
return (v: unknown): v is TypeMap[T] => typeof v === type
|
|
|
|
}
|
2022-11-08 01:19:15 +01:00
|
|
|
|
|
|
|
export function assertTypeExhausted(v: never): never {
|
|
|
|
throw new Error(`Type should be exhausted but is not. Value "${JSON.stringify(v)}`)
|
|
|
|
}
|