I've got a bunch of TypeScript code that calls getContext('2d') on HTML canvas elements.
Since the update to 1.5 beta this morning I now get a union type of CanvasRenderingContext2D and WebGLRenderingContext. That makes sense for the general call to getContext(...) since either could be returned.
However if I'm specifically calling getContext('2d'), I know I'm getting back a CanvasRenderingcontext2D.
I worked around it by creating this little interface in a file
interface HTMLCanvasElement {
getContext(contextId: '2d'): CanvasRenderingContext2D;
}
(using syntax from section 3.8.2.4 - Specialized Signatures in the TypeScript language reference)
Could we get this added to lib.d.ts perhaps?
I've got a bunch of TypeScript code that calls
getContext('2d')on HTML canvas elements.Since the update to 1.5 beta this morning I now get a union type of
CanvasRenderingContext2DandWebGLRenderingContext. That makes sense for the general call to getContext(...) since either could be returned.However if I'm specifically calling
getContext('2d'), I know I'm getting back aCanvasRenderingcontext2D.I worked around it by creating this little interface in a file
(using syntax from
section 3.8.2.4 - Specialized Signaturesin the TypeScript language reference)Could we get this added to lib.d.ts perhaps?