microsoft / microsoft/TypeScript

Support `export { x as default }` in namespace declarations

Open
#24,164 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Search Terms

Suggestion

options for allow use import { xxx } from 'yyy'; when TS2497 resolves to a non-module entity

without warn or use // @ts-ignore

Error:(11, 19) TS2305: Module has no exported member 'isGitRoot'.
Error:(11, 36) TS2497: Module resolves to a non-module entity and cannot be imported using this construct.

Use Cases

Examples

demo.ts

import gitRoot, { isGitRoot } from 'git-root2';

git-root2

declare function gitRoot(cwd?: string): string;
declare namespace gitRoot {
    function isGitRoot(target: string): boolean;
    function async(cwd?: string): Promise<string>;
}
declare const _default: typeof gitRoot & {
    gitRoot(cwd?: string): string;
    default(cwd?: string): string;
    async(cwd?: string): Promise<string>;
};
export = _default;

Checklist

My suggestion meets these guidelines:
[x] This wouldn't be a breaking change in existing TypeScript / JavaScript code
[x] This wouldn't change the runtime behavior of existing JavaScript code
[ ] This could be implemented without emitting different JS based on the types of the expressions
[ ] This isn't a runtime feature (e.g. new expression-level syntax)

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 demo.ts import and the declare namespace/export = example in the issue, then investigate the compiler behavior represented by TS2497 and TS2305. Done means the proposed namespace export form supports the shown import without a warning or ts-ignore, with the expected diagnostics covered by tests.

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.