You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I initially wanted to report to TypeScript that this doesn't typecheck (it reports Type 'URL' is not assignable to type 'string'.(2322)), until I discovered that the HTML spec itself doesn't allow for URL assignment: https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-src and it is a USVString (https://heycam.github.io/webidl/#idl-USVString). I am not deeply familiar with these contents, but as I understand the terminology, URL assignment would not be allowed.
Can we update the spec to allow for URLs to be assigned to the src property of an HTMLImageElement?
The text was updated successfully, but these errors were encountered:
The HTML spec already allows this. The trick is that the src setter, like all setters on HTML elements, does a conversion (in this case the conversion is named "USVString", which means ToString plus censoring surrogate pairs). Since URL defines a toString() method, it all works as you'd hope.
I'll close this since the HTML spec is fine as-is, but feel free to ask more questions in the closed thread!
Running the following code in Chrome and Firefox will be successful (wasn't able to verify what Safari does):
I initially wanted to report to TypeScript that this doesn't typecheck (it reports
Type 'URL' is not assignable to type 'string'.(2322)
), until I discovered that the HTML spec itself doesn't allow for URL assignment: https://html.spec.whatwg.org/multipage/embedded-content.html#dom-img-src and it is a USVString (https://heycam.github.io/webidl/#idl-USVString). I am not deeply familiar with these contents, but as I understand the terminology, URL assignment would not be allowed.Can we update the spec to allow for URLs to be assigned to the
src
property of an HTMLImageElement?The text was updated successfully, but these errors were encountered: