microsoft / microsoft/TypeScript
Allow type-only named re-exports along with assigned export in the same file
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
Search Terms
allow export types assigned =
Suggestion
The suggestion is to allow compilation of files that do both export = and export type {}.
Use Cases
For modules that target both TypeScript and CommonJS usage it would allow consolidating all exports for both module systems in one file (albeit with the requirement of esModuleInterop being true).
Currently, in order to do that I would have to utilize @ts-ignore (see parzh/xrange#69 for details).
Examples
/person.ts:
import personValue from "./person-value";
export = personValue;
export type { default as PersonType } from "./person-type";
/person-type.ts:
export default interface Person { name: string; }
/person-value.ts:
export default { name: "John Doe" } as import("./person-type").default;
Usage:
/usage.ts:
import personValue from "./person";
import personValue, { PersonType } from "./person";
import type { PersonType } from "./person";
import personValue = require("./person");
/usage.js:
const personValue = require("./person");
Checklist
My suggestion meets these guidelines:
- This wouldn't be a breaking change in existing TypeScript/JavaScript code
- 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. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- This feature would agree with the rest of TypeScript's Design Goals.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names the example files person.ts, person-type.ts, person-value.ts, and usage.ts, but no compiler files or tests. Start by locating how the compiler handles export = alongside type-only named exports, then verify the example compiles and that type-only exports do not alter emitted JavaScript.
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
- 30/100