Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Module augmentation does not work on un-imported node packages / generated d.ts files #8113

Copy link
Copy link
@theoy

Description

@theoy
Issue body actions

TypeScript Version: v1.8.10

  1. Create a basic external npm package 'node_modules/ext'. In it, set up the following 2 files:

    // ext.d.ts
    declare var _default: {};
    export default _default;
    
    // package.json (edit it)
      "main": "ext",
      "typings": "ext",
    
  2. Reference package 'ext' from A.ts, using --declaration, generating A.d.ts

    // A.ts
    import ext from 'ext';
    
    declare module 'ext' { }
    
  3. Copy A.d.ts to another directory, that has the ext package installed in node_modules
    // B.ts import * as modA from './A'

Expected behavior:
Generated A.d.ts causes no errors because typed package 'ext' was in the correct location.

Actual behavior:
A.d.ts(1,16): error TS2664: Invalid module name in augmentation, module 'ext' cannot be found.

Workarounds:

  • explicitly import 'ext' module while in B
  • re-export something from B as part of A (triggering an import to be generated in A.d.ts)

Remarks:
This is frustrating because the fact that A depended on 'ext' was an implementation detail, and in reality npm was the one that brought 'ext' into node_modules.

Thoughts?

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    CommittedThe team has roadmapped this issueThe team has roadmapped this issueFixedA PR has been merged for this issueA PR has been merged for this issueSuggestionAn idea for TypeScriptAn idea for TypeScript

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.