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
Add dom definition for canvas #61
Comments
We'll update the dom definitions to be sensitive to string arguments. |
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? |
What I would like, would be to be able to do something like: var canvas : HTMLCanvasElement = document.createElement('canvas'); In other words, |
+1 |
Script to regen test fixture
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. |
@lbolla Regarding your comment about 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. |
Summary: Fixes #819 See also #61 This _should_ work, but I'm running into another bug. `canvastest.js` produces this error instead of the expected one: ``` canvastest.js:4:11,29: call of method getContext Function cannot be called on [LIB] dom.js:649:5,14: HTMLCanvasElement Found 1 error ``` This is caused by overloading string parameters to `getContext` in `lib/dom.js`. If there's just one declaration, it works as expected. It looks like something similar is going on for the existing `createElement` declarations. For example, this line: ``` var el = document.createElement('canvas'); ``` produces this non-sense error: ``` canvastest.js:2:10,41: call of method createElement Function cannot be called on [LIB] dom.js:235:5,17: Document ``` @samwgoldman thoughts? Is this the same as #583? Closes #837 Reviewed By: @svcscm Differential Revision: D2540791 Pulled By: @gabelevi fb-gh-sync-id: 70484aabe0d2b78f9ed425493e0c63e4ac6c1ee1
document.createElement('canvas') returns a type HTMLElement, which does not define methods like "getContext". There should be a HTMLCanvasElement in dom.js similarly to HTMLImageElement.
The text was updated successfully, but these errors were encountered: