Skip to content

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

Closed

Description

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;

Activity

  1. DanielRosenwasser commented on Aug 10, 2016

    @DanielRosenwasser
    Member
  2. added
    Bug
    Domain: lib.d.ts
    on Aug 10, 2016
  3. added this to the milestone on Aug 18, 2016
  4. mhegazy commented on Aug 18, 2016

    @mhegazy
    Contributor
  5. CookieShade commented on Aug 19, 2016

    @CookieShade
    Author

    I'd make a PR, but I lack the Typescript experience and know-how to semantically fix the issue.

  6. mhegazy commented on Aug 20, 2016

    @mhegazy
    Contributor

    potentially put a readonly _tag: never field on the interface, that would make it unassingable from other types.

  7. modified the milestones: TypeScript 2.1, , on Oct 31, 2016
  8. added
    Fixed in TSJS repo
    on Oct 31, 2016
  9. added
    Fixed
    and removed
    Fixed in TSJS repo
    on Oct 31, 2016
  10. locked and limited conversation to collaborators on Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDomain: lib.d.tsFixed

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions