TypeScript Error: TS2345 [ERROR]: Argument of type 'string | URL' is not assignable to parameter of type 'string'.
See original GitHub issueIssue
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:
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:
- Created 3 years ago
- Comments:7 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello, I’m experiencing this issue using Opine
0.25.0
on Deno1.4.2
? ThanksThanks 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 aURL
as the first parameter.