Fix TS issues

This commit is contained in:
Dolan Miu
2023-05-31 22:56:58 +01:00
parent a26292a0fd
commit 352cde743f
6 changed files with 20 additions and 18 deletions

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { expect } from "chai";
import { Formatter } from "@export/formatter";
@ -203,7 +204,7 @@ describe("SectionProperties", () => {
});
const tree = new Formatter().format(properties);
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
const pgBorders = tree["w:sectPr"].find((item) => item["w:pgBorders"] !== undefined);
const pgBorders = tree["w:sectPr"].find((item: any) => item["w:pgBorders"] !== undefined);
expect(pgBorders).to.deep.equal({
"w:pgBorders": { _attr: { "w:offsetFrom": "page" } },
});
@ -219,7 +220,7 @@ describe("SectionProperties", () => {
});
const tree = new Formatter().format(properties);
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
const pgNumType = tree["w:sectPr"].find((item) => item["w:pgNumType"] !== undefined);
const pgNumType = tree["w:sectPr"].find((item: any) => item["w:pgNumType"] !== undefined);
expect(pgNumType).to.deep.equal({
"w:pgNumType": { _attr: { "w:fmt": "upperRoman" } },
});
@ -229,7 +230,7 @@ describe("SectionProperties", () => {
const properties = new SectionProperties({});
const tree = new Formatter().format(properties);
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
const pgNumType = tree["w:sectPr"].find((item) => item["w:pgNumType"] !== undefined);
const pgNumType = tree["w:sectPr"].find((item: any) => item["w:pgNumType"] !== undefined);
expect(pgNumType).to.deep.equal({ "w:pgNumType": { _attr: {} } });
});
@ -239,7 +240,7 @@ describe("SectionProperties", () => {
});
const tree = new Formatter().format(properties);
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
const type = tree["w:sectPr"].find((item) => item["w:type"] !== undefined);
const type = tree["w:sectPr"].find((item: any) => item["w:type"] !== undefined);
expect(type).to.deep.equal({
"w:type": { _attr: { "w:val": "continuous" } },
});
@ -256,7 +257,7 @@ describe("SectionProperties", () => {
});
const tree = new Formatter().format(properties);
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
const type = tree["w:sectPr"].find((item) => item["w:lnNumType"] !== undefined);
const type = tree["w:sectPr"].find((item: any) => item["w:lnNumType"] !== undefined);
expect(type).to.deep.equal({
"w:lnNumType": { _attr: { "w:countBy": 2, "w:distance": 4, "w:restart": "continuous", "w:start": 2 } },
});
@ -270,7 +271,7 @@ describe("SectionProperties", () => {
});
const tree = new Formatter().format(properties);
expect(Object.keys(tree)).to.deep.equal(["w:sectPr"]);
const type = tree["w:sectPr"].find((item) => item["w:textDirection"] !== undefined);
const type = tree["w:sectPr"].find((item: any) => item["w:textDirection"] !== undefined);
expect(type).to.deep.equal({
"w:textDirection": { _attr: { "w:val": "tbRl" } },
});

View File

@ -26,18 +26,16 @@ export interface IDrawingOptions {
// </xsd:complexType>
export class Drawing extends XmlComponent {
private readonly inline: Inline;
public constructor(imageData: IMediaData, drawingOptions: IDrawingOptions = {}) {
super("w:drawing");
if (!drawingOptions.floating) {
this.inline = new Inline({
const inline = new Inline({
mediaData: imageData,
transform: imageData.transformation,
docProperties: drawingOptions.docProperties,
});
this.root.push(this.inline);
this.root.push(inline);
} else {
this.root.push(new Anchor(imageData, imageData.transformation, drawingOptions));
}

View File

@ -26,7 +26,7 @@ describe("Numbering", () => {
const tree = new Formatter().format(numbering);
expect(Object.keys(tree)).to.deep.equal(["w:numbering"]);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const abstractNums: readonly any[] = tree["w:numbering"].filter((el) => el["w:abstractNum"]);
const abstractNums: readonly any[] = tree["w:numbering"].filter((el: any) => el["w:abstractNum"]);
expect(abstractNums).to.have.lengthOf(1);
expect(abstractNums[0]["w:abstractNum"]).to.deep.include.members([
{ _attr: { "w:abstractNumId": 0, "w15:restartNumberingAfterBreak": 0 } },

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { expect } from "chai";
import { Formatter } from "@export/formatter";
@ -15,7 +16,7 @@ describe("Styles", () => {
},
],
});
const tree = new Formatter().format(styles)["w:styles"].filter((x) => !x._attr);
const tree = new Formatter().format(styles)["w:styles"].filter((x: any) => !x._attr);
expect(tree).to.deep.equal([
{
"w:style": { _attr: { "w:type": "paragraph", "w:styleId": "pStyleId" } },
@ -32,7 +33,7 @@ describe("Styles", () => {
},
],
});
const tree = new Formatter().format(styles)["w:styles"].filter((x) => !x._attr);
const tree = new Formatter().format(styles)["w:styles"].filter((x: any) => !x._attr);
expect(tree).to.deep.equal([
{
"w:style": [
@ -53,7 +54,7 @@ describe("Styles", () => {
},
],
});
const tree = new Formatter().format(styles)["w:styles"].filter((x) => !x._attr);
const tree = new Formatter().format(styles)["w:styles"].filter((x: any) => !x._attr);
expect(tree).to.deep.equal([
{
"w:style": [
@ -82,7 +83,7 @@ describe("Styles", () => {
},
],
});
const tree = new Formatter().format(styles)["w:styles"].filter((x) => !x._attr);
const tree = new Formatter().format(styles)["w:styles"].filter((x: any) => !x._attr);
expect(tree).to.deep.equal([
{
"w:style": [

View File

@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* tslint:disable:no-unused-expression */
import { expect } from "chai";
@ -344,10 +345,10 @@ describe("Table", () => {
});
const tree = new Formatter().format(table);
expect(tree).to.have.property("w:tbl").which.is.an("array");
const row = tree["w:tbl"].find((x) => x["w:tr"]);
const row = tree["w:tbl"].find((x: any) => x["w:tr"]);
expect(row).not.to.be.undefined;
expect(row["w:tr"]).to.be.an("array").which.has.length.at.least(1);
expect(row["w:tr"].find((x) => x["w:tc"])).to.deep.equal({
expect(row["w:tr"].find((x: any) => x["w:tc"])).to.deep.equal({
"w:tc": [
{
"w:p": [

View File

@ -123,7 +123,8 @@ export const patchDocument = async (data: InputDataType, options: PatchDocumentO
return element;
}
}),
},
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} as any,
patchText,
renderedParagraphs,
context,