TypeScript Version: 3.6.4
Though the types are still the same
|
declare var URL: { |
|
prototype: URL; |
|
new(url: string, base?: string | URL): URL; |
|
createObjectURL(object: any): string; |
|
revokeObjectURL(url: string): void; |
|
}; |
Search Terms:
undefined URL constructor base argument Safari
Code
class FooURL {
private _url: URL
constructor(url: string, base?: string | URL) {
this._url = new URL(url, base)
}
}
// Throws `TypeError: Type error` in Safari
new FooURL('https://example.com')
Expected behavior:
The constructor for URL should not allow undefined constructor argument for base
Something more appropriate could look like
new(url: string): URL;
new(url: string, base: string | URL): URL;
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 valid
Other 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
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
undefinedconstructor argument forbaseSomething 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
baseconstructor 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-generatorgenerates 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