1 import TaxReturn from './TaxReturn';
2 import { Line } from './Line';
3 import { InconsistencyError, NotFoundError } from './Errors';
5 export default abstract class Form<L extends { [key: string]: Line<any> },
7 abstract readonly name: string;
9 protected abstract readonly _lines: L;
11 readonly supportsMultipleCopies: boolean = false;
13 private readonly _input?: I;
15 constructor(input?: I) {
19 getLine<K extends keyof L>(id: K): L[K] {
20 if (!(id in this._lines))
21 throw new NotFoundError(`Form ${this.name} does not have line ${id}`);
22 const line = this._lines[id];
23 // We cannot apply this to every line in the constructor because |_lines|
24 // is abstract, so do it on getLine().
29 getValue<K extends keyof L>(tr: TaxReturn, id: K): ReturnType<L[K]['value']> {
30 const line: L[K] = this.getLine(id);
31 return line.value(tr);
34 getInput<K extends keyof I>(name: K): I[K] {
35 if (!(name in this._input)) {
36 throw new NotFoundError(`No input with key ${name} on form ${this.name}`);
38 return this._input[name];