UNPKG

@marcelohmdias/vue-typed

Version:

The easiest way to define types in Vue props

133 lines (132 loc) 3.05 kB
import { PropOptions, PropType } from 'vue'; declare type PropValidator<T> = (value: T) => boolean; declare type PropDefault<T> = T | null | undefined | (() => T | null | undefined); interface TypedInstance { array: TypedInstance; bool: TypedInstance; check<T>(validator: PropValidator<T>): TypedInstance; date: TypedInstance; def(): PropOptions<any>; func: TypedInstance; num: TypedInstance; obj: TypedInstance; required: TypedInstance; str: TypedInstance; sym: TypedInstance; type<T>(type: PropType<T>): TypedInstance; with<T>(value: PropDefault<T>): TypedInstance; } export default class Typed { private props; /** * Create a new instance of Typed * * @readonly * @static * @type {TypedInstance} * @memberof Typed */ static get is(): TypedInstance; /** * Set Prop as required * * @readonly * @type {TypedInstance} * @memberof Typed */ get required(): TypedInstance; /** * Set Prop type to Array * * @readonly * @type {TypedInstance} * @memberof Typed */ get array(): TypedInstance; /** * Set Prop type to Boolean * * @readonly * @type {TypedInstance} * @memberof Typed */ get bool(): TypedInstance; /** * Set Prop type to Date * * @readonly * @type {TypedInstance} * @memberof Typed */ get date(): TypedInstance; /** * Set Prop type to Function * * @readonly * @type {TypedInstance} * @memberof Typed */ get func(): TypedInstance; /** * Set Prop type to Number * * @readonly * @type {TypedInstance} * @memberof Typed */ get num(): TypedInstance; /** * Set Prop type to Object * * @readonly * @type {TypedInstance} * @memberof Typed */ get obj(): TypedInstance; /** * Set Prop type to String * * @readonly * @type {TypedInstance} * @memberof Typed */ get str(): TypedInstance; /** * Set Prop type to Symbol * * @readonly * @type {TypedInstance} * @memberof Typed */ get sym(): TypedInstance; /** * Returns a new Prop setting * * @type {PropOptions<any>} * @memberof Typed */ def(): PropOptions<any>; /** * Assigns a new default value to Prop * * @param {PropDefault<T>} value * @memberof Typed */ with<T>(value: PropDefault<T>): TypedInstance; /** * Defines a new type for Prop * * @readonly * @type {TypedInstance} * @memberof Typed */ type<T>(type: PropType<T>): TypedInstance; /** * Assigns a validator to Prop * * @param {PropValidator<T>} validator * @memberof Typed */ check<T>(validator: PropValidator<T>): TypedInstance; } export {};