Typescript: globalThis, Unsafe assignment of an `any` value
See original GitHub issueVersion 3.0.0-beta.9
I’m trying to patch the global object in typescript
import fetch from "node-fetch"
if (!globalThis.fetch) {
globalThis.fetch = fetch
}
And I get this error
Type 'typeof fetch' is not assignable to type '(input: RequestInfo, init?: RequestInit | undefined) => Promise<Response>'.
Types of parameters 'url' and 'input' are incompatible.
Type 'RequestInfo' is not assignable to type 'import("node_modules/node-fetch/@types/index").RequestInfo'.
Type 'Request' is not assignable to type 'RequestInfo'.
Type 'Request' is missing the following properties from type 'Body': size, bufferts
Issue Analytics
- State:
- Created 2 years ago
- Reactions:8
- Comments:9 (2 by maintainers)
Top Results From Across the Web
Using globalThis in Typescript - Stack Overflow
This turns this file into an ES module, which is necessary for this to work. You can export any of the statements or...
Read more >The starting point for learning TypeScript
TypeScript Documentation. Get Started. Quick introductions based on your background or preference. TS for the New Programmer · TypeScript for JS ...
Read more >Non-null assertions should not be used - SonarSource Rules
The point of declaring an optional property or parameter is to make explicit the fact that it might contain no valid value, i.e....
Read more >Understanding TypeScript Configuration Options
Introducing how TypeScript configuration options work. TypeScript ... recursively matches any subdirectory ... TypeScript will detect the unsafe assignment:
Read more >Optional chaining (?.) - JavaScript - MDN Web Docs - Mozilla
The value of obj.first is confirmed to be non- null (and non- undefined ) ... for the member bar in a map when...
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 FreeTop 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
Top GitHub Comments
use top level await with es6 modules and conditionally load node-fetch instead
still complains? use
// @ts-ignore
Potentially something like this could work?