Skip to content

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

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

Closed
CookieShade opened this issue Aug 5, 2016 · 4 comments
Closed

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

CookieShade opened this issue Aug 5, 2016 · 4 comments
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this

Comments

@CookieShade
Copy link

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;
@DanielRosenwasser
Copy link
Member

Looks like it should have a tag or something.

For reference: https://developer.mozilla.org/en-US/docs/Web/API/CanvasPattern

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Aug 10, 2016
@mhegazy mhegazy added this to the Community milestone Aug 18, 2016
@mhegazy mhegazy added the Help Wanted You can do this label Aug 18, 2016
@mhegazy
Copy link
Contributor

mhegazy commented Aug 18, 2016

PRs welcomed. You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes.

@CookieShade
Copy link
Author

CookieShade commented Aug 19, 2016

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

@mhegazy
Copy link
Contributor

mhegazy commented Aug 20, 2016

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

@mhegazy mhegazy modified the milestones: TypeScript 2.1, Community, TypeScript 2.1.2 Oct 31, 2016
@mhegazy mhegazy added the Fixed in TSJS repo Fix merged in https://github.com/Microsoft/TSJS-lib-generator, but not ported yet label Oct 31, 2016
@mhegazy mhegazy added Fixed A PR has been merged for this issue and removed Fixed in TSJS repo Fix merged in https://github.com/Microsoft/TSJS-lib-generator, but not ported yet labels Oct 31, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Fixed A PR has been merged for this issue Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

4 participants