readonly name = 'F1';
protected readonly _lines = {
'1': new InputLine<Input>('key'),
- '2': new InputLine<Input>('key2')
+ '2': new InputLine<Input>('key2'),
+ '3': new InputLine<Input>('key2', undefined, 'FALLBACK')
};
};
const tr = new TaxReturn(2019);
const l2 = f.getLine('2');
expect(() => l2.value(tr)).toThrow(NotFoundError);
+
+ expect(f.getLine('3').value(tr)).toBe('FALLBACK');
});
test('line stack', () => {
export class InputLine<U = unknown, T extends keyof U = any> extends Line<U[T]> {
private _input: T;
+ private _fallback: U[T];
form: Form<any, U>;
- constructor(input: T, description?: string) {
+ constructor(input: T, description?: string, fallback?: U[T]) {
super(description || `Input from ${input}`);
this._input = input;
+ this._fallback = fallback;
}
value(tr: TaxReturn): U[T] {
+ if (!this.form.hasInput(this._input) && this._fallback !== undefined)
+ return this._fallback;
return this.form.getInput<T>(this._input);
}
};