Skip to content

[lib.d.ts] Incorrect typing for CanvasPattern #10184

Closed
@CookieShade

Description

@CookieShade

TypeScript Version: 1.8.34

Code

let canvas = document.createElement("canvas");
let context = canvas.getContext("2d");

let pattern: CanvasPattern = []; // !!!
context.fillStyle = pattern;
context.strokeStyle = 0; // !!!

Expected behavior:
Fails to compile due to [] and 0 not being valid CanvasPatterns.

Actual behavior:
Successfully compiles, probably due to CanvasPattern being declared as an empty interface, which is obviously implemented by all objects. At runtime, the style is solid black.

// lib.d.ts
interface CanvasPattern {
}
//...
fillStyle: string | CanvasGradient | CanvasPattern;
//...
strokeStyle: string | CanvasGradient | CanvasPattern;

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptFixedA PR has been merged for this issueHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions