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

Built-in URL is not compatible with @types/node URL #59996

Open
noahbald opened this issue Sep 18, 2024 · 0 comments
Open

Built-in URL is not compatible with @types/node URL #59996

noahbald opened this issue Sep 18, 2024 · 0 comments
Assignees
Labels
Needs Investigation This issue needs a team member to investigate its status.

Comments

@noahbald
Copy link

⚙ Compilation target

es6

⚙ Library

lib.dom.d.ts

Missing / Incorrect Definition

I get an error after updating from 5.5.4 -> 5.6.2 because the builtin URL is not longer compatible with node's URL. This is problematic because the builtin URL and node's URL are often used interchangeably.
Even if their types aren't strictly the same, I'd normally expect there not to be an error when using one in place of the other.

In the following example, the line where we use new URL(origin) has an error because import("url") doesn't match the builtin URL.
Perhaps the typing of @types/node need to be updated?

error TS2345: Argument of type 'string | import("url").URL' is not assignable to parameter of type 'string | URL'.
  Type 'URL' is not assignable to type 'string | URL'.
    Type 'import("url").URL' is not assignable to type 'URL'.
      The types returned by 'searchParams.entries()' are incompatible between these types.
        Type 'IterableIterator<[string, string]>' is missing the following properties from type 'URLSearchParamsIterator<[string, string]>': map, filter, take, drop, and 9 more.

Sample Code

// agent.ts
import { URL } from 'url';

export function agent(url: URL | string) {/* ... */};

// factory.ts
const createAgent = (origin: Parameters<typeof agent>[0]) => {
  const { protocol } = new URL(origin);
  // ...
}

Documentation Link

This was probably introduces as part of the strict iterator checks
https://devblogs.microsoft.com/typescript/announcing-typescript-5-6/#strict-builtin-iterator-checks-(and---strictbuiltiniteratorreturn)

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Sep 18, 2024
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 5.7.0 milestone Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Investigation This issue needs a team member to investigate its status.
Projects
None yet
Development

No branches or pull requests

3 participants