tbluemel / rtf.js

Render RTF documents in HTML.
MIT License
147 stars 36 forks source link

Module won't compile #76

Closed taco-indenbosch closed 3 years ago

taco-indenbosch commented 3 years ago

Hi,

I am trying to use this module in an NX monorepo (http://nx.dev) using Angular 11, but the module will not compile. I get the following error messages:

> nx run portal:build
√ Browser application bundle generation complete.

Error: node_modules/rtf.js/dist/src/emfjs/GDIContext.d.ts:7:5 - error TS2411: Property 'brush' of type 'Brush | undefined' is not assignable to string index type 'Obj'.

7     brush?: Brush;
      ~~~~~
node_modules/rtf.js/dist/src/emfjs/GDIContext.d.ts:8:5 - error TS2411: Property 'pen' of type 'Pen | undefined' is not assignable to string index type 'Obj'.

8     pen?: Pen;
      ~~~
node_modules/rtf.js/dist/src/emfjs/GDIContext.d.ts:9:5 - error TS2411: Property 'font' of type 'Font | undefined' is not assignable to string index type 'Obj'.

9     font?: Font;
      ~~~~
node_modules/rtf.js/dist/src/emfjs/GDIContext.d.ts:10:5 - error TS2411: Property 'region' of type 'Region | undefined' is not assignable to string index type 'Obj'.

10     region?: Region;
       ~~~~~~
node_modules/rtf.js/dist/src/emfjs/GDIContext.d.ts:11:5 - error TS2411: Property 'path' of type 'Path | undefined' is not assignable to string index type 'Obj'.

11     path?: Path;
       ~~~~
node_modules/rtf.js/dist/src/wmfjs/GDIContext.d.ts:8:5 - error TS2411: Property 'brush' of type 'Brush | undefined' is not assignable to string index type 'Obj'.

8     brush?: Brush;
      ~~~~~
node_modules/rtf.js/dist/src/wmfjs/GDIContext.d.ts:9:5 - error TS2411: Property 'pen' of type 'Pen | undefined' is not assignable to string index type 'Obj'.

9     pen?: Pen;
      ~~~
node_modules/rtf.js/dist/src/wmfjs/GDIContext.d.ts:10:5 - error TS2411: Property 'font' of type 'Font | undefined' is not assignable to string index type 'Obj'.

10     font?: Font;
       ~~~~
node_modules/rtf.js/dist/src/wmfjs/GDIContext.d.ts:11:5 - error TS2411: Property 'palette' of type 'Palette | undefined' is not assignable to string index type 'Obj'.

11     palette?: Palette;
       ~~~~~~~
node_modules/rtf.js/dist/src/wmfjs/GDIContext.d.ts:12:5 - error TS2411: Property 'region' of type 'Region | undefined' is not assignable to string index type 'Obj'.

12     region?: Region;

the error messages go away if I change GDIContext.d.ts from

export interface ISelectedStyle {
    brush?: Brush;
    pen?: Pen;
    font?: Font;
    region?: Region;
    path?: Path;

    [key: string]: Obj;
}

to

export interface ISelectedStyle {
    brush?: Brush;
    pen?: Pen;
    font?: Font;
    region?: Region;
    path?: Path;

    [key: string]: Obj | undefined;
}

Is there something I am doing wrong or is the above fix actually necessary?

zoehneto commented 3 years ago

I assume the problem is, that you run typescript with strict null checks while this project doesn't use strict null checks (as retrofitting it is too much work). Now your typescript compiler checks our published typings with strict null checks and notices that it won't work.

As a quick fix you should be able to get everything to compile by setting skipLibCheck (see documentation here). I've also created a PR with the fix you mentioned so if that is the only issue you're seeing (I don't use rtf.js in any projects with typescript and strict null checks so I can't test this right now) it should be fixed by the PR. I would appreciate it if you could test this.

taco-indenbosch commented 3 years ago

I have tested the changes in the branch nullability-in-typings and they solve my problem.