Revert "Make SupportsMultipleCopies an interface."
authorRobert Sesek <rsesek@bluestatic.org>
Fri, 21 Feb 2020 13:34:08 +0000 (08:34 -0500)
committerRobert Sesek <rsesek@bluestatic.org>
Fri, 21 Feb 2020 15:16:12 +0000 (10:16 -0500)
This reverts commit 26177f7e25370d27e6e2f04857269129a74d1f44.

src/Form.ts
src/Line.test.ts
src/TaxReturn.test.ts
src/TaxReturn.ts
src/fed2019/FormW2.ts

index e3d6c4e7de613ad8bb18eb2d3b7d9d8014284f1a..5fe5862316645fff25097ddf93a57d1c8970e4df 100644 (file)
@@ -8,6 +8,8 @@ export default abstract class Form<I = unknown> {
 
   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<I = unknown> {
     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;
-};
index f49b29485be5faee6e8bee95cbb2c8500f36d738..2c6558ae56476712db57ad9ee3f06a1a8b691205 100644 (file)
@@ -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<number>('g', 100.25) ]
index 788222cc6260555a13c2f98b239dcd918aef3325..b327918d2d94e65faa8555104a5447500ae11181 100644 (file)
@@ -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 []; }
   };
index 23a00ad2fbd24b01a50984dae2ccabef0051275d..c7f1003a303dccbc76867e06f1ec108ddf17661e 100644 (file)
@@ -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}`);
index bb0c0ec72f29fd99547e5dd5628e1e91d1f9b7de..e61f83c8e3adbef56baec47015c8985090b1ef4d 100644 (file)
@@ -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<T extends keyof W2Input> extends InputLine<W2Input, T> {};
 
-export default class W2 extends Form<W2Input> implements SupportsMultipleCopies {
+export default class W2 extends Form<W2Input> {
   get name(): string { return 'W-2'; }
 
+  readonly supportsMultipleCopies = true;
+
   aggregate(f: Form[]): this { return null; }
 
   protected getLines(): Line<any>[] {