homebridge-prometheus-exporter/src/std.ts
2022-11-07 15:23:48 +01:00

11 lines
302 B
TypeScript

type Types = 'string' | 'number' | 'boolean' | 'object'
type TypeMap = {
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
}