Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 1x 1x 1x 3x 1x 2x 1x 1x | import type { ValidParameterTypeName, RawParameterType } from '../ValidParameterTypeName'; import type { IParameterBuilder } from './IParameterBuilder'; export class OptionalParameterBuilder<TypeName extends ValidParameterTypeName, T> implements IParameterBuilder<TypeName | 'object' | 'undefined', T | null> { public constructor( private readonly builder: IParameterBuilder<TypeName, T> ) {} public get expectedTypes(): Set<TypeName | 'object' | 'undefined'> { return new Set<TypeName | 'object' | 'undefined'>(this.builder.expectedTypes) .add('object') .add('undefined'); } public build(value: RawParameterType<TypeName | 'object' | 'undefined'>): T | null { if (value === null) return null; if (typeof value === 'object' && !(this.builder.expectedTypes as Set<string>).has('object')) throw new Error('Value is unexpected an object.'); return this.builder.build(value as RawParameterType<TypeName>); } } |