@types/typescript does not work with `import` syntax
See original GitHub issueReproduce by running the following in an empty directory:
npm init
npm i yargs
echo "import yargs from 'yargs';" > index.ts
tsc index.ts
We get the error
index.ts:1:19 - error TS2307: Cannot find module 'yargs' or its corresponding type declarations.
1 import yargs from 'yargs'
~~~~~~~
Found 1 error.
Reproduced with yargs 16.0.3
and tsc 4.0.2
.
Issue Analytics
- State:
- Created 3 years ago
- Comments:15 (6 by maintainers)
Top Results From Across the Web
Documentation - TypeScript 3.8
TypeScript 3.8 adds a new syntax for type-only imports and exports. ... When using import type to import a class, you can't do...
Read more >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 >10 Insights from Adopting TypeScript at Scale | Bloomberg LP
An example of new declaration syntax is the emit of getter/setter ... This is similar to the problem that import maps attempt to...
Read more >Usage With TypeScript - Redux
This allows you to import them into any component file that needs to use the hooks, and avoids potential circular import dependency issues....
Read more >babel/types
Aliases: Standardized , Scopable , Function , BlockParent , FunctionParent ... t.import(); ... FunctionParent did not include Program since Babel 7.
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
https://github.com/yargs/yargs#typescript yargs doesn’t ship built-in types yet, so one has to install
@types/yargs
as well.@bcoe you can already
import yargs as 'yargs';
if you haveesModuleInterop
turned on (default intsc --init
) and@types/yargs
in place. We do so in stylable: https://github.com/wix/stylable/blob/master/packages/cli/src/cli.tsWe are getting yargs in its
require
form though, as our modules transpile to commonjs (meaning arequire('yargs')
is being called).EDIT: just to clarify…
esModuleInterop
causesallowSyntheticDefaultImports
to be turned on, which causes the type checker to allow importing “commonjs modules” (.d.ts
saysexport =
) using default import.