Angular 角度11和PdfMake。错误TS2345:类型为{…}的参数不能分配给类型为TDocumentDefinitions的参数

Angular 角度11和PdfMake。错误TS2345:类型为{…}的参数不能分配给类型为TDocumentDefinitions的参数,angular,pdfmake,Angular,Pdfmake,我正试图根据Angular 11应用程序中pdfMake的官方文档定义pdf文档结构。但是收到一个错误: error TS2345: Argument of type '{ pageSize: string; pageOrientation: string; content: ({ text: string; style: string; fontSize?: undefined; } | { text: string; fontSize: number; style?: undefined;

我正试图根据Angular 11应用程序中pdfMake的官方文档定义pdf文档结构。但是收到一个错误:

error TS2345: Argument of type '{ pageSize: string; pageOrientation: string; content: ({ text: string; style: string; fontSize?: undefined; } | { text: string; fontSize: number; style?: undefined; })[]; }' is not assignable to parameter of type 'TDocumentDefinitions'.
  Types of property 'pageOrientation' are incompatible.
    Type 'string' is not assignable to type '"landscape" | "portrait" | undefined'.

75     pdfMake.createPdf(docDefinition).open();
我已安装了所有员工:

npm install --save pdfmake
npm i --save-dev @types/pdfmake
并将其输入:

import * as pdfMake from "pdfmake/build/pdfmake";
import * as pdfFonts from 'pdfmake/build/vfs_fonts';
(<any>pdfMake).vfs = pdfFonts.pdfMake.vfs;
当我从方法属性定义pageSizepageOrientation中删除时,会出现错误。
我还缺少什么?

在查看Stackoverflow上的一些帖子后,我找到了一个解决方案。问题在于在TypeScrpit中使用pdfMake库(枚举类型)(本文中描述)

因此,我将pdfMake库的导入更改为

import * as pdfMake from "pdfmake/build/pdfmake"; 

然后由npm安装节点类型

npm i @types/node
最后在Angular app根目录中的tsconfig.app.json文件中做了一些更改(在第行的方括号中添加“节点”):

更改后:

"types": ["node"]
就这些。编译器最终开始理解文档定义中的所有内容类型,以便在pdfMake库中的createPdf方法中生成pdf

npm i @types/node
"types": []
"types": ["node"]