From 83dad03f8cd0de961dc122a6f8c5cd8e61dd578b Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Thu, 20 Feb 2020 18:49:58 -0500 Subject: [PATCH] Further improve the typing of InputLine to not require the `as any` cast. --- src/Line.test.ts | 4 ++-- src/Line.ts | 10 +++++----- src/fed2019/FormW2.ts | 32 ++++++++++++++++---------------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/Line.test.ts b/src/Line.test.ts index 0d658c2..f49b294 100644 --- a/src/Line.test.ts +++ b/src/Line.test.ts @@ -62,8 +62,8 @@ test('input line', () => { protected getLines() { return [ - new InputLine('1', 'key'), - new InputLine('2', 'key2') + new InputLine('1', 'key'), + new InputLine('2', 'key2') ]; } }; diff --git a/src/Line.ts b/src/Line.ts index 212fd61..5e4773b 100644 --- a/src/Line.ts +++ b/src/Line.ts @@ -53,18 +53,18 @@ export class ReferenceLine extends Line { } }; -export class InputLine extends Line { - private _input: keyof U; +export class InputLine extends Line { + private _input: T; form: Form; - constructor(id: string, input: keyof U, description?: string) { + constructor(id: string, input: T, description?: string) { super(id, description); this._input = input; } - value(tr: TaxReturn): T { - return this.form.getInput(this._input) as any; + value(tr: TaxReturn): U[T] { + return this.form.getInput(this._input); } }; diff --git a/src/fed2019/FormW2.ts b/src/fed2019/FormW2.ts index a0ca2d9..bb0c0ec 100644 --- a/src/fed2019/FormW2.ts +++ b/src/fed2019/FormW2.ts @@ -31,7 +31,7 @@ export interface W2Input { box14?: CodeAndAmount[]; }; -class Input extends InputLine {}; +class Input extends InputLine {}; export default class W2 extends Form implements SupportsMultipleCopies { get name(): string { return 'W-2'; } @@ -40,21 +40,21 @@ export default class W2 extends Form implements SupportsMultipleCopies protected getLines(): Line[] { return [ - new Input('c', 'employer', 'Employer name'), - new Input('e', 'employee', 'Emplyee name'), - new Input('1', 'wages', 'Wages, tips, other compensation'), - new Input('2', 'fedIncomeTax', 'Federal income tax withheld'), - new Input('3', 'socialSecurityWages', 'Social security wages'), - new Input('4', 'socialSecuirtyTax', 'Social security tax withheld'), - new Input('5', 'medicareWages', 'Medicare wages and tips'), - new Input('6', 'medicareTax', 'Medicare tax withheld'), - new Input('7', 'socialSecurityTips', 'Social security tips'), - new Input('8', 'allocatedTips', 'Allocated tips'), - new Input('10', 'dependentCareBenefits', 'Dependent care benefits'), - new Input('11', 'nonqualifiedPlans','Nonqualified plans'), - new Input('12', 'box12', 'Box 12'), - new Input('13', 'box13', 'Box 13'), - new Input('14', 'box14', 'Other'), + new Input('c', 'employer', 'Employer name'), + new Input('e', 'employee', 'Emplyee name'), + new Input('1', 'wages', 'Wages, tips, other compensation'), + new Input('2', 'fedIncomeTax', 'Federal income tax withheld'), + new Input('3', 'socialSecurityWages', 'Social security wages'), + new Input('4', 'socialSecuirtyTax', 'Social security tax withheld'), + new Input('5', 'medicareWages', 'Medicare wages and tips'), + new Input('6', 'medicareTax', 'Medicare tax withheld'), + new Input('7', 'socialSecurityTips', 'Social security tips'), + new Input('8', 'allocatedTips', 'Allocated tips'), + new Input('10', 'dependentCareBenefits', 'Dependent care benefits'), + new Input('11', 'nonqualifiedPlans','Nonqualified plans'), + new Input('12', 'box12', 'Box 12'), + new Input('13', 'box13', 'Box 13'), + new Input('14', 'box14', 'Other'), ]; } }; -- 2.22.5