Try this:
var canvas: HTMLCanvasElement;
canvas = document.createElement("canvas");
Blows up with
/private/var/folders/07/jtkf72yn4_587wv8zc7ntg6h0000gn/T/flow_bjorn/flowlib_282271de/lib/dom.js:301:1,316:1: HTMLElement
This type is incompatible with
/private/var/folders/07/jtkf72yn4_587wv8zc7ntg6h0000gn/T/flow_bjorn/flowlib_282271de/lib/dom.js:326:1,332:1: HTMLCanvasElement
Doesn't seem right. If I make it just an HTMLElement it blows up when I try to use the getContext method on canvas.
document.createElement returns an HTMLElement.
Imagine some code like:
var x = document.createElement(someInputFromuser);
And you can see why Flow can't know at check time which type of DOM element x is.
var canvas = document.createElement("canvas");
if (!(canvas instanceof HTMLCanvasElement)) {
return;
}
canvas.getContext(); // works here
Ok got it, thanks!
Most helpful comment
document.createElementreturns anHTMLElement.Imagine some code like:
var x = document.createElement(someInputFromuser);And you can see why Flow can't know at check time which type of DOM element x is.