From aeee032cd25c8b063586c5b4fe1274fdfa4ac79f Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Fri, 21 Feb 2020 08:34:08 -0500 Subject: [PATCH] Revert "Make SupportsMultipleCopies an interface." This reverts commit 26177f7e25370d27e6e2f04857269129a74d1f44. --- src/Form.ts | 10 ++-------- src/Line.test.ts | 6 +++--- src/TaxReturn.test.ts | 6 +++--- src/TaxReturn.ts | 4 ++-- src/fed2019/FormW2.ts | 6 ++++-- 5 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/Form.ts b/src/Form.ts index e3d6c4e..5fe5862 100644 --- a/src/Form.ts +++ b/src/Form.ts @@ -8,6 +8,8 @@ export default abstract class Form { abstract get name(): string; + readonly supportsMultipleCopies: boolean = false; + constructor(input?: I) { this._input = input; this.getLines().map(this.addLine.bind(this)); @@ -49,11 +51,3 @@ export default abstract class 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; -}; diff --git a/src/Line.test.ts b/src/Line.test.ts index f49b294..2c6558a 100644 --- a/src/Line.test.ts +++ b/src/Line.test.ts @@ -1,5 +1,5 @@ import { Line, AccumulatorLine, InputLine, ReferenceLine, ComputedLine } from './Line'; -import Form, { SupportsMultipleCopies } from './Form'; +import Form from './Form'; import TaxReturn from './TaxReturn'; import { NotFoundError } from './Errors'; @@ -106,10 +106,10 @@ test('line stack', () => { }); test('accumulator line', () => { - class TestForm extends Form implements SupportsMultipleCopies { + class TestForm extends Form { get name() { return 'Form B'; } - aggregate() { return null; } + readonly supportsMultipleCopies = true; protected getLines() { return [ new ConstantLine('g', 100.25) ] diff --git a/src/TaxReturn.test.ts b/src/TaxReturn.test.ts index 788222c..b327918 100644 --- a/src/TaxReturn.test.ts +++ b/src/TaxReturn.test.ts @@ -1,6 +1,6 @@ import TaxReturn from './TaxReturn'; import Person from './Person'; -import Form, { SupportsMultipleCopies } from './Form'; +import Form from './Form'; import { NotFoundError, InconsistencyError } from './Errors'; test('constructor', () => { @@ -67,10 +67,10 @@ test('single-copy forms', () => { }); test('multiple-copy forms', () => { - class TestForm extends Form implements SupportsMultipleCopies { + class TestForm extends Form { get name(): string { return 'Test Form'; } - aggregate(forms: Form[]): this { return null; } + readonly supportsMultipleCopies = true; protected getLines() { return []; } }; diff --git a/src/TaxReturn.ts b/src/TaxReturn.ts index 23a00ad..c7f1003 100644 --- a/src/TaxReturn.ts +++ b/src/TaxReturn.ts @@ -1,4 +1,4 @@ -import Form, { SupportsMultipleCopies, supportsMultipleCopies } from './Form'; +import Form from './Form'; import Person, { Relation } from './Person'; import { NotFoundError, InconsistencyError, UnsupportedFeatureError } from './Errors'; @@ -38,7 +38,7 @@ export default class TaxReturn { } addForm(form: Form) { - if (!supportsMultipleCopies(form)) { + if (!form.supportsMultipleCopies) { const other = this.getForms(form.name); if (other.length > 0) { throw new InconsistencyError(`Cannot have more than one type of form ${form.name}`); diff --git a/src/fed2019/FormW2.ts b/src/fed2019/FormW2.ts index bb0c0ec..e61f83c 100644 --- a/src/fed2019/FormW2.ts +++ b/src/fed2019/FormW2.ts @@ -1,4 +1,4 @@ -import Form, { SupportsMultipleCopies } from '../Form'; +import Form from '../Form'; import { Line, InputLine } from '../Line'; import Person from '../Person'; @@ -33,9 +33,11 @@ export interface W2Input { class Input extends InputLine {}; -export default class W2 extends Form implements SupportsMultipleCopies { +export default class W2 extends Form { get name(): string { return 'W-2'; } + readonly supportsMultipleCopies = true; + aggregate(f: Form[]): this { return null; } protected getLines(): Line[] { -- 2.22.5