From a45048a4640a76fa1c39e0da475c9f273037db8d Mon Sep 17 00:00:00 2001 From: felipe Date: Fri, 10 Mar 2017 17:45:16 +0100 Subject: [PATCH] fix a handful of strict null errors; make test config also be strict These errors only arose because I didn't run `npm build`, only `npm test`. Then, when I tried building the null checks failed. Keeping the two config fiels in sync will help prevent this issue in the future --- ts/docx/table/grid.ts | 4 +++- ts/docx/table/index.ts | 2 +- ts/test-tsconfig.json | 5 +++++ ts/tests/docx/table/testGrid.ts | 12 +----------- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/ts/docx/table/grid.ts b/ts/docx/table/grid.ts index 91c38ddd21..3731891177 100644 --- a/ts/docx/table/grid.ts +++ b/ts/docx/table/grid.ts @@ -14,6 +14,8 @@ class GridColAttributes extends XmlAttributeComponent<{w: number}> { export class GridCol extends XmlComponent { constructor(width?: number) { super("w:gridCol"); - this.root.push(new GridColAttributes({w: width})); + if (width !== undefined) { + this.root.push(new GridColAttributes({w: width})); + } } } diff --git a/ts/docx/table/index.ts b/ts/docx/table/index.ts index f205f9a96b..485dc4fcf4 100644 --- a/ts/docx/table/index.ts +++ b/ts/docx/table/index.ts @@ -23,7 +23,7 @@ export class Table extends XmlComponent { this.rows = []; for (let i = 0; i < rows; i++) { - const cells = []; + const cells: TableCell[] = []; for (let j = 0; j < cols; j++) { cells.push(new TableCell()); } diff --git a/ts/test-tsconfig.json b/ts/test-tsconfig.json index 844ea999ff..255c0e089c 100644 --- a/ts/test-tsconfig.json +++ b/ts/test-tsconfig.json @@ -1,7 +1,12 @@ { "compilerOptions": { "target": "es6", + "strictNullChecks": true, + "sourceMap": true, + "removeComments": true, + "preserveConstEnums": true, "outDir": "../build-tests", + "sourceRoot": "./", "rootDir": "./", "module": "commonjs" } diff --git a/ts/tests/docx/table/testGrid.ts b/ts/tests/docx/table/testGrid.ts index edb0b50d4b..5eb234fd29 100644 --- a/ts/tests/docx/table/testGrid.ts +++ b/ts/tests/docx/table/testGrid.ts @@ -15,9 +15,7 @@ describe("GridCol", () => { it("does not set a width attribute if not given", () => { const grid = new GridCol(); const tree = new Formatter().format(grid); - expect(tree).to.deep.equal({ - "w:gridCol": [{_attr: {}}], - }); + expect(tree).to.deep.equal({"w:gridCol": []}); }); }); }); @@ -35,13 +33,5 @@ describe("TableGrid", () => { ], }); }); - - it("does not set a width attribute if not given", () => { - const grid = new GridCol(); - const tree = new Formatter().format(grid); - expect(tree).to.deep.equal({ - "w:gridCol": [{_attr: {}}], - }); - }); }); });