question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript Error: TS2345 [ERROR]: Argument of type 'string | URL' is not assignable to parameter of type 'string'.

See original GitHub issue

Issue

Setup:

  • deno 1.2.0
  • v8 8.5.216
  • typescript 3.9.2
  • opine main at 2295ba25be8320e0a3adfb5fe9d53477b02d1650

(Also checked with the latest v0.18.0)

Details

When running my program:

// mod.ts
import {opine} from "https://deno.land/x/opine@main/mod.ts";

const app = opine();

app.get('/', (req, res) => {
    res.send('Hello Deno Land 🦕');
});

app.listen(3000);
console.log("running at htpss://localhost:3000");

with the command: deno run mod.ts

I get the following error:

error: TS2345 [ERROR]: Argument of type 'string | URL' is not assignable to parameter of type 'string'.
  Type 'URL' is not assignable to type 'string'.
  return new URL(url).pathname
                 ~~~
    at https://deno.land/std@0.60.0/path/win32.ts:917:18

TS2345 [ERROR]: Argument of type 'string | URL' is not assignable to parameter of type 'string'.
  Type 'URL' is not assignable to type 'string'.
  return new URL(url).pathname;
                 ~~~
    at https://deno.land/std@0.60.0/path/posix.ts:438:18

TS2345 [ERROR]: Argument of type 'string | URL' is not assignable to parameter of type 'string'.
  Type 'URL' is not assignable to type 'string'.
  return new URL(url).pathname
                 ~~~
    at https://deno.land/std@0.58.0/path/win32.ts:917:18

TS2345 [ERROR]: Argument of type 'string | URL' is not assignable to parameter of type 'string'.
  Type 'URL' is not assignable to type 'string'.
  return new URL(url).pathname;
                 ~~~
    at https://deno.land/std@0.58.0/path/posix.ts:438:18

TS2345 [ERROR]: Argument of type 'ParsedURL' is not assignable to parameter of type 'string'.
    const loc = encodeUrl(new URL(originalUrl).toString());
                                  ~~~~~~~~~~~
    at https://deno.land/x/opine@main/src/middleware/serveStatic.ts:227:35

Found 5 errors.

I’ve traced the issue to these two lines:

https://github.com/asos-craigmorten/opine/blob/2295ba25be8320e0a3adfb5fe9d53477b02d1650/src/middleware/serveStatic.ts#L227

https://github.com/asos-craigmorten/opine/blob/2295ba25be8320e0a3adfb5fe9d53477b02d1650/src/utils/parseUrl.ts#L70

I believe this is an error in type and should be addressed. I cannot run my program at this time. Let me know if you agree this is the issue and I can try to implement a fix.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
KaKi87commented, Oct 26, 2020

Hello, I’m experiencing this issue using Opine 0.25.0 on Deno 1.4.2 ? Thanks

1reaction
asos-craigmortencommented, Jul 14, 2020

Thanks for raising this @srepollock!

Having followed the issue on GitHub and Discord, and reading the changelog I still managed to overlook this 🤦

Relevant issues / PRs:

It’s annoying that it deviates from what browsers / node allow, but the Deno team are aiming to write to WHATWG spec.

Should be simple enough to fix, we just need to cast to string as the URL constructor no longer accepts a URL as the first parameter.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Argument type URL is not assignable to parameter type string
Like the error says, you're giving a URL where a string is expected. If you want to keep using the type URL for...
Read more >
URL' is not assignable to parameter of type 'string' · Issue #6755
error : TS2345 [ERROR]: Argument of type 'string | URL' is not assignable to parameter of type 'string'. Type 'URL' is not assignable...
Read more >
Argument of type 'string or undefined' is not assignable to ...
The error "Argument of type string | undefined is not assignable to parameter of type string" occurs when a possibly undefined value is...
Read more >
Documentation - Everyday Types - TypeScript
JavaScript has three very commonly used primitives: string , number , and boolean . ... Argument of type 'number' is not assignable to...
Read more >
argument of type 'string' is not assignable to parameter of type ...
pathname; ~~~ at https://deno.land/std@0.55.0/path/posix.ts:438:18 TS2345 [ERROR]: Argument of type 'string | URL' is not assignable to parameter of type ' ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found