schema/items/literal.ts

14 lines
357 B
TypeScript

import SchemaItem from "../SchemaItem"
export default class SchemaLiteral<Type> extends SchemaItem<Type> {
public constructor(private readonly value: Type) {
super(arguments)
this.validations.push({ fn: (value) => value === this.value })
}
public override isOfType(input: unknown): input is Type {
return typeof input === typeof this.value
}
}