Skip to content

Poor error guidance for deep imports of packages with @types #24781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
DanielRosenwasser opened this issue Jun 8, 2018 · 1 comment
Closed
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging Fixed A PR has been merged for this issue @types Relates to working with .d.ts files (declaration/definition files) from DefinitelyTyped

Comments

@DanielRosenwasser
Copy link
Member

DanielRosenwasser commented Jun 8, 2018

yarn init --yes
yarn add @types/acorn@4.0.3

With noImplicitAny:

import * as acorn from "acorn/dist/acorn_loose";

Error:

Could not find a declaration file for module 'acorn/dist/acorn_loose'. 'c:/Users/Daniel/sample/node_modules/acorn/dist/acorn_loose.js' implicitly has an 'any' type.
  Try `npm install @types/acorn` if it exists or add a new declaration (.d.ts) file containing `declare module 'acorn';`

But @types/acorn already has been installed. The true error is that the declaration files haven't been written for this deeper import. I think we can give a better error message here.

@DanielRosenwasser DanielRosenwasser added Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging @types Relates to working with .d.ts files (declaration/definition files) from DefinitelyTyped labels Jun 8, 2018
@mhegazy mhegazy assigned ghost Jun 8, 2018
@mhegazy mhegazy added this to the TypeScript 3.0 milestone Jun 8, 2018
@mhegazy
Copy link
Contributor

mhegazy commented Jun 8, 2018

The suggestion here is to make the error more helpful by checking the existence of the top-level package.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: Error Messages The issue relates to error messaging Fixed A PR has been merged for this issue @types Relates to working with .d.ts files (declaration/definition files) from DefinitelyTyped
Projects
None yet
Development

No branches or pull requests

2 participants