GithubHelp home page GithubHelp logo

Add dom definition for canvas about flow HOT 6 CLOSED

facebook avatar facebook commented on April 19, 2024
Add dom definition for canvas

from flow.

Comments (6)

avikchaudhuri avatar avikchaudhuri commented on April 19, 2024

We'll update the dom definitions to be sensitive to string arguments.

from flow.

rajsite avatar rajsite commented on April 19, 2024

When performing a createElement('canvas') the type can be known from the string, but how would you annotate getElementById('mycanvas') to type as HTMLCanvasElement instead of HTMLElement?

from flow.

lbolla avatar lbolla commented on April 19, 2024

What I would like, would be to be able to do something like:

var canvas : HTMLCanvasElement = document.createElement('canvas');
var mycanvas : HTMLCanvasElement = document.getElementById('mycanvas');

In other words, createElement and getElementById would be polimorphic. I don't know if Flow supports such feature.

from flow.

agentcooper avatar agentcooper commented on April 19, 2024

+1

from flow.

 avatar commented on April 19, 2024

Thank you for reporting this issue and appreciate your patience. We've notified the core team for an update on this issue. We're looking for a response within the next 30 days or the issue may be closed.

from flow.

samwgoldman avatar samwgoldman commented on April 19, 2024

createElement("canvas") does currently return a HTMLCanvasElement, so this issue is resolved.

@lbolla Regarding your comment about getElementById returning a specific HTMLElement subtype—Flow does not do that, and it is unsafe to do. Flow doesn't know what HTML the code will execute against, and therefore doesn't know anything more specific.

This is a great use case for dynamic type tests.

var canvas = document.getElementById("mycanvas");
if (canvas instanceof HTMLCanvasElement) {
  // good to go -- type of canvas is refined this block
} else {
  // error condition -- provide some useful debug info
}

I see this as a good thing. Flow is helping you out and directing you to add error handling to make your code safer.

from flow.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.