microsoft / microsoft/TypeScript

Allow augmentation of re-exported module

Open
#12,607 15 comments 16 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Experience Enhancement Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

I've sadly discovered that it not possible to augment a ES2015 module that is being re-exported. At least not without specifying the full path to the ES2015 that is then being re-exported.

This has significant implications, particularly for library authors and consumers.

An example would probably help clarify.

Suppose as an authored of a library I want to expose a simple surface area from which consumers should import from. I do this by creating an index.ts file that re-exports modules from nested sub-folders like so:

// index.ts
export { AClass } from './path/to/class-a';
export { BClass } from './path/to/class-b';
export { CClass } from './path/to/class-c';

Now a consumer can import like so:

import { AClass, BClass } from 'some-library'; 

The benefits of the above:

  1. As library author I am free to reorganise the modules into sub-folders as the library code base grows without breaking consumers
  2. As library consumer I don't need to have intimate knowledge of how the library organises it's file on disk - instead I have one path to import modules and this is the name of the npm package itself.

Once augmentation enters the picture all of the above benefits are now gone.

This is really bad for everyone.

What can be done about the situation?

Thanks
Christian

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the re-export pattern shown in index.ts and compare augmentation through the package entry point with augmentation through the full nested module path. The issue does not name compiler files or tests; done would mean consumers can augment a re-exported module without depending on the library's internal file layout.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.