microsoft / PowerBI-visuals-tools

Contains tools for building/packaging Power BI visuals
https://www.powerbi.com
MIT License
330 stars 149 forks source link

Unable to use "strict": true in tsconfig #428

Closed ElPrudi closed 1 year ago

ElPrudi commented 2 years ago

When I enable "strict": true in my tsconfig.json, I get these errors:

ERROR in C:\Dev\VSCode\Power BI\circleCard\.tmp\precompile\visualPlugin.ts
./.tmp/precompile/visualPlugin.ts 13:4-10
[tsl] ERROR in C:\Dev\VSCode\Power BI\circleCard\.tmp\precompile\visualPlugin.ts(13,5)
      TS2322: Type '(options: VisualConstructorOptions) => Visual' is not assignable to type '(options?: VisualConstructorOptions | undefined) => IVisual'.
  Types of parameters 'options' and 'options' are incompatible.
    Type 'VisualConstructorOptions | undefined' is not assignable to type 'VisualConstructorOptions'.
      Type 'undefined' is not assignable to type 'VisualConstructorOptions'.
ts-loader-default_e3b0c44298fc1c14

ERROR in C:\Dev\VSCode\Power BI\circleCard\.tmp\precompile\visualPlugin.ts
./.tmp/precompile/visualPlugin.ts 20:42-56
[tsl] ERROR in C:\Dev\VSCode\Power BI\circleCard\.tmp\precompile\visualPlugin.ts(20,43)
      TS7017: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
ts-loader-default_e3b0c44298fc1c14

webpack 5.74.0 compiled with 2 errors in 360 ms

I can't exclude it from my tsconfig, as it has a direct dependency to the visual.ts in the src folder.

AleksSavelev commented 1 year ago

It's fixed in the last versions.

Syntarex commented 1 year ago

The latest version didn't fix it for me.

What helped is to set the constructor's parameter to optional. Like so:

constructor(options?: VisualConstructorOptions) {
        // Fixes stupid shitty bug: https://github.com/microsoft/PowerBI-visuals-tools/issues/428
        if (!options) {
            return;
        }

        // DO YOUR STUFF
    }
AleksSavelev commented 9 months ago

@Syntarex Thanks for additional info. Yes, this is necessary to do it in your constructor, because now options is optional. It was did this way to match PowerBI API and allow to use it in strict mode.