镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

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

Description

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.

Activity

  1. added
    BugA bug in TypeScript
    @typesRelates to working with .d.ts files (declaration/definition files) from DefinitelyTyped
    on Jun 8, 2018
  2. mhegazy commented on Jun 8, 2018

    @mhegazy
    Contributor

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

  3. ghost added
    FixedA PR has been merged for this issue
    on Jun 8, 2018
  4. ghost closed this as completedin #24815on Jun 21, 2018
  5. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    @typesRelates to working with .d.ts files (declaration/definition files) from DefinitelyTypedBugA bug in TypeScriptDomain: Error MessagesThe issue relates to error messagingFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions