protected abstract getLines(): Line<any>[];
- get allowMultipleCopies(): boolean {
- return false;
- }
-
private addLine(line: Line<any>) {
if (line.form !== undefined) {
throw new InconsistencyError('Line is already in a Form');
return this._input[name];
}
};
+
+export interface SupportsMultipleCopies extends Form {
+ aggregate(forms: Form[]): this;
+};
+
+export function supportsMultipleCopies(f: object): f is SupportsMultipleCopies {
+ return f instanceof Form && 'aggregate' in f;
+};
import TaxReturn from './TaxReturn';
import { Person } from './Person';
-import Form from './Form';
+import Form, { SupportsMultipleCopies } from './Form';
import { NotFoundError, InconsistencyError } from './Errors';
test('constructor', () => {
});
test('multiple-copy forms', () => {
- class TestForm extends Form {
+ class TestForm extends Form implements SupportsMultipleCopies {
get name(): string { return 'Test Form'; }
- get allowMultipleCopies(): boolean { return true; }
+ aggregate(forms: Form[]): this { return null; }
protected getLines() { return []; }
};
-import Form from './Form';
+import Form, { SupportsMultipleCopies, supportsMultipleCopies } from './Form';
import { Person, Relation } from './Person';
import { NotFoundError, InconsistencyError, UnsupportedFeatureError } from './Errors';
}
addForm(form: Form) {
- if (!form.allowMultipleCopies) {
+ if (!supportsMultipleCopies(form)) {
const other = this.getForms(form.name);
if (other.length > 0) {
throw new InconsistencyError(`Cannot have more than one type of form ${form.name}`);