Imports don't work in typescript
See original GitHub issueI’d like to directly import required types, and not utilize the types
field in tsconfig.json
.
During development it all seems to work fine, but whenever I run wrangler dev
I get errors like this:
No matching export in "node_modules/@cloudflare/workers-types/2022-08-04/index.ts" for import "Response"
.
What’s the correct way to import?
Issue Analytics
- State:
- Created 10 months ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Import statement does not work in typescript - Stack Overflow
Then I'm trying to import a class in a file using 'import' keyword. But despite having read about the declaration of modules in...
Read more >Imports not working in TypeScript project. · Issue #199 - GitHub
When I am trying to import any of the Props into a TypeScript project, import sizes from "open-props/src/sizes" I get a ts(2307) Error:...
Read more >Common TypeScript module problems and how to solve them
Resolving modules in multiple locations can be a bit challenging because at this point in your code, the compiler does not know how...
Read more >Documentation - Modules - TypeScript
Often modules extend other modules, and partially expose some of their features. A re-export does not import it locally, or introduce a local...
Read more >3 Different Ways to Import Modules in TypeScript | by Wei Kang
If we were to use this method to import modules without installing the @types/node package, we will have a complaint from TypeScript as...
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
I think this might be a case of us not being clear enough in documentation—we can definitely try and improve that!
To clarify, you’re able to import types directly if your use case will fit within the constraints of
import type {...}
, which essentially require that they can be fully stripped out at build time, and have no runtime component. When you doimport { Response } from "@cloudflare/workers-types/experimental"
, and use it asnew Response()
, typescript is unable to strip out theResponse
import at build time, as it’s used at runtime. For that use case, usingtsconfig.json
is the recommended way forward.We intend for the importable types to be used in cases where you have to also use libdom, and situations like that. If you’re just writing a worker, using
tsconfig.json
will most closely reflect the actual runtime types available to your code.I’d say the documentation is somewhat vague about it, as it mentions “which are usable with no additional tsconfig.json setup”. Which I interpreted as importing without referencing the types in
tsconfig.json
. I assumed that workerd strips or ignores the related imports.Ideally it should be possible to explicitly import without messing with
tsconfig.json
.This issue can be closed if you see this is a non-issue.