From 22db1518f3952af1330d9388adf98cd51bceebfe Mon Sep 17 00:00:00 2001 From: Benoit Benezech Date: Mon, 1 May 2017 18:02:37 +0200 Subject: [PATCH] Fix canvas getContext signature in lib/lib.dom.d.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit According to https://developer.mozilla.org/en/docs/Web/API/HTMLCanvasElement/getConte xt, it only returns `null if the context identifier is not supported` (i.e. not “2d” | "webgl" | "experimental-webgl”, when new non-standard renderers are omitted). This fix might make some people happy: this error generates tons of useless and annoying non-null `!` type casts when working with canvases. --- lib/lib.dom.d.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/lib.dom.d.ts b/lib/lib.dom.d.ts index 94fb13c32ed0b..bd3c0e0977a31 100644 --- a/lib/lib.dom.d.ts +++ b/lib/lib.dom.d.ts @@ -4339,9 +4339,9 @@ interface HTMLCanvasElement extends HTMLElement { * Returns an object that provides methods and properties for drawing and manipulating images and graphics on a canvas element in a document. A context object includes information about colors, line widths, fonts, and other graphic parameters that can be drawn on a canvas. * @param contextId The identifier (ID) of the type of canvas to create. Internet Explorer 9 and Internet Explorer 10 support only a 2-D context using canvas.getContext("2d"); IE11 Preview also supports 3-D or WebGL context using canvas.getContext("experimental-webgl"); */ - getContext(contextId: "2d", contextAttributes?: Canvas2DContextAttributes): CanvasRenderingContext2D | null; - getContext(contextId: "webgl" | "experimental-webgl", contextAttributes?: WebGLContextAttributes): WebGLRenderingContext | null; - getContext(contextId: string, contextAttributes?: {}): CanvasRenderingContext2D | WebGLRenderingContext | null; + getContext(contextId: "2d", contextAttributes?: Canvas2DContextAttributes): CanvasRenderingContext2D; + getContext(contextId: "webgl" | "experimental-webgl", contextAttributes?: WebGLContextAttributes): WebGLRenderingContext; + getContext(contextId: string, contextAttributes?: {}): null; /** * Returns a blob object encoded as a Portable Network Graphics (PNG) format from a canvas image or drawing. */