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
classFooURL{private_url: URLconstructor(url: string,base?: string|URL){this._url=newURL(url,base)}}// Throws `TypeError: Type error` in SafarinewFooURL('https://example.com')
Expected behavior:
The constructor for URL should not allow undefined constructor argument for base
Both Safari Version 13.0.2 (14608.2.40.1.3), and Safari Technology Preview Release 94 (Safari 13.1, WebKit 14609.1.6.1) throw an error when the base constructor argument is undefined.
Essentially typescript treats new URL('example.com', undefined) as valid
Other browsers are able to handle this case just fine.
TS doesn't really distinguish between passing undefined to a function vs skipping the argument entirely. This is convenient 95% of the time and the remaining 5% breaks libraries that are written in an indirection-hostile way. Anyway we're not here to encode Safari's spec compliance bugs into our lib file.
TypeScript Version: 3.6.4
Though the types are still the same
TypeScript/lib/lib.dom.d.ts
Lines 16068 to 16073 in a03227d
Search Terms:
undefined URL constructor base argument Safari
Code
Expected behavior:
The constructor for URL should not allow
undefined
constructor argument forbase
Something more appropriate could look like
Actual behavior:
Both Safari Version 13.0.2 (14608.2.40.1.3), and Safari Technology Preview Release 94 (Safari 13.1, WebKit 14609.1.6.1) throw an error when the
base
constructor argument is undefined.Essentially typescript treats
new URL('example.com', undefined)
as validOther browsers are able to handle this case just fine.
I did look at the whatwg spec
Maybe it's a problem with how
TSJS-lib-generator
generates optional arguments?I'm not sure if this is something that should be handled by TypeScript. Interested to hear what others think!
Playground Link
Related Issues:
#15246
The text was updated successfully, but these errors were encountered: