Skip to content

bug: TS7016 Could not find a declaration file for module #14379

Closed
@ikatyang

Description

@ikatyang

TypeScript Version: 2.2.1 / nightly (2.3.0-dev.20170301)

Command

tsc try.ts --noImplicitAny

Code

try.ts

import { x } from 'test'; // error TS7016: Could not find a declaration file for module 'test'.

module test

  • package.json

    {
      "name": "test",
      "version": "1.0.0",
      "main": "lib/index"
    }
  • lib/index.js

    "use strict";
    exports.__esModule = true;
    exports.x = { test: "only" };
  • lib/index.d.ts

    export interface X {
      test: "only";
    }
    export declare const x: X;

Expected behavior:

non-error

Actual behavior:

try.ts(1,19): error TS7016: Could not find a declaration file for module 'test'. '~/tsc-test/node_modules/test/lib/index.js' implicitly has an 'any' type.

It works fine with [email protected], or specified types field in package.json:

{
  "name": "test",
  "version": "1.0.0",
  "main": "lib/index",
  "types": "lib/index"
}

But I think this is a bug, since the documentation said:

Also note that if your main declaration file is named index.d.ts and lives at the root of the package (next to index.js) you do not need to mark the "types" property, though it is advisable to do so.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions