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.

@types/typescript does not work with `import` syntax

See original GitHub issue

Reproduce 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:closed
  • Created 3 years ago
  • Comments:15 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
AviVahlcommented, Sep 10, 2020

https://github.com/yargs/yargs#typescript yargs doesn’t ship built-in types yet, so one has to install @types/yargs as well.

1reaction
AviVahlcommented, Sep 10, 2020

@bcoe you can already import yargs as 'yargs'; if you have esModuleInterop turned on (default in tsc --init) and @types/yargs in place. We do so in stylable: https://github.com/wix/stylable/blob/master/packages/cli/src/cli.ts

We are getting yargs in its require form though, as our modules transpile to commonjs (meaning a require('yargs') is being called).

EDIT: just to clarify… esModuleInterop causes allowSyntheticDefaultImports to be turned on, which causes the type checker to allow importing “commonjs modules” (.d.ts says export =) using default import.

Read more comments on GitHub >

github_iconTop 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 >

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