Skip to content
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

new URL() does not take URL object as base parameter #15246

Closed
felixfbecker opened this issue Apr 18, 2017 · 6 comments
Closed

new URL() does not take URL object as base parameter #15246

felixfbecker opened this issue Apr 18, 2017 · 6 comments
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this
Milestone

Comments

@felixfbecker
Copy link
Contributor

TypeScript Version: 2.3.0

Code

// A *self-contained* demonstration of the problem follows...
const base = new URL('http://foo.com')
new URL('bar.html', base) 

Expected behavior:
Should compile

Actual behavior:

[ts]
Argument of type 'URL' is not assignable to parameter of type 'string | undefined'.
  Type 'URL' is not assignable to type 'string'.

Reference: https://developer.mozilla.org/en-US/docs/Web/API/URL/URL

@felixfbecker felixfbecker changed the title new URL() does not take URL as base parameter new URL() does not take URL object as base parameter Apr 18, 2017
@RyanCavanaugh
Copy link
Member

RyanCavanaugh commented Apr 18, 2017

The WG definition clearly defines this as a string https://url.spec.whatwg.org/#constructors , so the ability to pass a URL is just an implicit string conversion. Not sure why MDN documents this as if it's a different constructor.

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript labels Apr 18, 2017
@RyanCavanaugh
Copy link
Member

... but the spec also shows an implicit string conversion as an example usage, so we should play along

@RyanCavanaugh RyanCavanaugh added the Help Wanted You can do this label Apr 18, 2017
@felixfbecker
Copy link
Contributor Author

Yeah, you are right. It seems to accept URL objects for both input and base.

@mhegazy mhegazy added this to the Community milestone Apr 18, 2017
@mhegazy
Copy link
Contributor

mhegazy commented Apr 18, 2017

PRs welcomed. You can find more information about contributing lib.d.ts fixes at https://github.com/Microsoft/TypeScript/blob/master/CONTRIBUTING.md#contributing-libdts-fixes.

@TimvdLippe
Copy link
Contributor

microsoft/TypeScript-DOM-lib-generator#332 has been merged and the update has been incorporated in this repository per https://github.com/Microsoft/TypeScript/blob/f2a1a428ea99ace495a8ca769b0a7c857ea6486a/lib/lib.dom.d.ts#L14860

@BarryThePenguin
Copy link

I think this can be closed now? It looks like the latest lib.dom.d.ts supports this

new(url: string, base?: string | URL): URL;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: lib.d.ts The issue relates to the different libraries shipped with TypeScript Help Wanted You can do this
Projects
None yet
Development

No branches or pull requests

5 participants