Skip to content

Clarify canvas ctx.globalCompositeOperation type #34673

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
Joncom opened this issue Oct 23, 2019 · 2 comments
Closed

Clarify canvas ctx.globalCompositeOperation type #34673

Joncom opened this issue Oct 23, 2019 · 2 comments
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript
Milestone

Comments

@Joncom
Copy link

Joncom commented Oct 23, 2019

TypeScript Version: 3.6.4

Search Terms:

globalCompositeOperation, TypeScript, union

Code:

The valid strings for ctx.globalCompositeOperation can be viewed here: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/globalCompositeOperation

For example, this is valid:

ctx.globalCompositeOperation = 'source-in';

However, this is invalid:

ctx.globalCompositeOperation = 'foo';

And yet TypeScript thinks both are valid, because TypeScript simply defines globalCompositeOperation as string:

TypeScript/lib/lib.dom.d.ts

Lines 3376 to 3379 in 29becf0

interface CanvasCompositing {
globalAlpha: number;
globalCompositeOperation: string;
}

The following union would provide a better development experience:

 'source-over' | 'source-in' | 'source-out' | 'source-atop' | 'destination-over' | 'destination-in' | 'destination-out' | 'destination-atop' | 'lighter' | 'copy' | 'xor' | 'multiply' | 'screen' | 'overlay' | 'darken' | 'lighten' | 'color-dodge' | 'color-burn' | 'hard-light' | 'soft-light' | 'difference' | 'exclusion' | 'hue' | 'saturation' | 'color' | 'luminosity'
@Joncom Joncom changed the title Canvas ctx.globalCompositeOperater to have more precise type Canvas ctx.globalCompositeOperation to have more precise type Oct 23, 2019
@Joncom Joncom changed the title Canvas ctx.globalCompositeOperation to have more precise type Clarify canvas ctx.globalCompositeOperation type Oct 23, 2019
@RyanCavanaugh RyanCavanaugh added the Bug A bug in TypeScript label Oct 30, 2019
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Oct 30, 2019
@RyanCavanaugh RyanCavanaugh added the Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript label Oct 30, 2019
@dhaig
Copy link

dhaig commented Nov 24, 2021

I opened a PR with these typings over in the DOM-lib-generator repo: microsoft/TypeScript-DOM-lib-generator#1206

@jakebailey
Copy link
Member

The above was pull into main in #47445.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants