Skip to content

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

Closed
@theoy

Description

@theoy

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions