Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Property 'setData' in type 'BarElement' is not assignable to the same property in base type 'CanvasElement<BarData>'. #236

Open
EagleLizard opened this issue Aug 19, 2022 · 0 comments

Comments

@EagleLizard
Copy link

Fresh install of blessed and blessed-contrib.

Typescript v4.6.3

Duplicate of #208, which was closed by original poster without clear justification.

The error presents itself with my original tsconfig.json:

{
  "compilerOptions": {
    "target": "es2015",
    "module": "commonjs",
    "outDir": "./dist",
    "noImplicitAny": true,
    "sourceMap": true,
    "esModuleInterop": true,
    "resolveJsonModule": true
  },
  "include": [
    "./src/main.ts"
  ],
  "exclude": [
    "node_modules",
    "dist"
  ]
}

Per #208, their new tsconfig set compilerOptions.skipLibCheck to true - this does not fix the issue, but hides it by not type checking the type declaration. Adding the flag allows it to compile; however, the types are still incorrect.

The full error I get:

node_modules/blessed-contrib/index.d.ts:134:13 - error TS2416: Property 'setData' in type 'BarElement' is not assignable to the same property in base type 'CanvasElement<BarData>'.
  Type '(data: BarData) => void' is not assignable to type '{ (data: BarData): void; (titles: string[], data: BarData): void; }'.
    Types of parameters 'data' and 'titles' are incompatible.
      Type 'string[]' has no properties in common with type 'BarData'.

134             setData(data: BarData): void;
                ~~~~~~~

node_modules/blessed-contrib/index.d.ts:277:13 - error TS2416: Property 'setData' in type 'GaugeElement' is not assignable to the same property in base type 'CanvasElement<any>'.
  Type '{ (percent: number[]): void; (percent: number): void; }' is not assignable to type '{ (data: any): void; (titles: string[], data: any): void; }'.
    Types of parameters 'percent' and 'titles' are incompatible.
      Type 'string[]' is not assignable to type 'number[]'.
        Type 'string' is not assignable to type 'number'.

277             setData(percent: number[]): void;
                ~~~~~~~

node_modules/blessed-contrib/index.d.ts:278:13 - error TS2416: Property 'setData' in type 'GaugeElement' is not assignable to the same property in base type 'CanvasElement<any>'.
  Type '{ (percent: number[]): void; (percent: number): void; }' is not assignable to type '{ (data: any): void; (titles: string[], data: any): void; }'.

278             setData(percent: number): void;
                ~~~~~~~

Seems to have been introduced in 4.8.21 via #206, which adds the parameter overload for CanvasElement.setData to accept non-generic string titles which introduces the type compatibility.

Removing the overloaded function signature seems to resolve the errors without skipping type checks in the tsconfig. Perhaps instead fo changing the generic type, the SparklineElement class could implement a custom setData signature as a special case?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant