InputLine needs to take the Form's generic.
authorRobert Sesek <rsesek@bluestatic.org>
Thu, 20 Feb 2020 06:08:19 +0000 (01:08 -0500)
committerRobert Sesek <rsesek@bluestatic.org>
Thu, 20 Feb 2020 06:08:19 +0000 (01:08 -0500)
The refactor in b51c88b40714d3b7183fd593c9e4496ff5dc7162 had failing
tests that was hidden by Jest's cache.

src/Line.test.ts
src/Line.ts

index c0f76ef3b0ebaa18cf7694ae88b532a8a7661a17..135bd922ce02b061522793ba703f386ffd6ad1b1 100644 (file)
@@ -53,13 +53,17 @@ test('reference line', () => {
 });
 
 test('input line', () => {
+  interface Input {
+    key: string;
+    key2?: string;
+  }
   class TestForm extends Form {
     get name() { return 'F1'; }
 
     protected getLines() {
       return [
-        new InputLine<string>('1', 'key'),
-        new InputLine<string>('2', 'key2')
+        new InputLine<string, Input>('1', 'key'),
+        new InputLine<string, Input>('2', 'key2')
       ];
     }
   };
@@ -77,7 +81,7 @@ test('line stack', () => {
     get name() { return 'Z'; }
 
     protected getLines() {
-      return [ new InputLine('3', 'input') ];
+      return [ new InputLine<any, any>('3', 'input') ];
     }
   };
 
index 0dd1b329a4d4c5d21e8ac3030a9c82825dd1c178..f4beb7d07ff26d4d9d8cef7d6b06641d3ccb12a2 100644 (file)
@@ -53,15 +53,17 @@ export class ReferenceLine<T> extends Line<T> {
   }
 };
 
-export class InputLine<T> extends Line<T> {
-  private _input: string;
+export class InputLine<T, U = unknown> extends Line<T> {
+  private _input: keyof U;
 
-  constructor(id: string, input: string, description?: string) {
+  form: Form<U>;
+
+  constructor(id: string, input: keyof U, description?: string) {
     super(id, description);
     this._input = input;
   }
 
   value(tr: TaxReturn): T {
-    return this.form.getInput<T>(this._input);
+    return this.form.getInput(this._input) as any;
   }
 };