import { identity } from '../src/from'; import { Type } from '../src/type'; import { InputOf, OutputOf } from '../src/from'; export const number: Type = { async from(str) { const decoded = parseInt(str, 10); if (Number.isNaN(decoded)) { throw new Error('Not a number'); } else { return decoded; } }, displayName: 'number', description: 'a number', }; export function single>( t: T ): Omit & Type[], OutputOf> { return { ...t, from(ts) { if (ts.length === 0) { return { result: 'error', message: `No value provided` }; } if (ts.length > 1) { return { result: 'error', message: `Too many arguments provided. Expected 1, got: ${ts.length}`, }; } return t.from(ts[0]); }, }; } export const string: Type = { ...identity(), description: 'a string', displayName: 'str', }; export const boolean: Type = { ...identity(), description: 'a boolean', displayName: 'true/false', defaultValue() { return false; }, }; export function optional>( t: T ): Type, OutputOf | undefined> { return { ...t, defaultValue(): OutputOf | undefined { return undefined; }, }; }