Repository: TypeScript
Issue: Allow export type along with export = statement
Labels: Suggestion,Awaiting More Feedback

# Suggestion

<!--
  Please fill in each section completely. Thank you!
-->

## 🔍 Search Terms

<!--
  💡 Did you know? TypeScript has over 2,000 open suggestions!
  🔎 Please search thoroughly before logging new feature requests as most common ideas already have a proposal in progress.
  The "Common Feature Requests" section of the FAQ lists many popular requests: https://github.com/Microsoft/TypeScript/wiki/FAQ#common-feature-requests

  Replace the text below:
-->

List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.

export =, type

## ✅ Viability Checklist

<!--
   Suggestions that don't meet all these criteria are very, very unlikely to be accepted.
   We always recommend reviewing the TypeScript design goals before investing time writing
   a proposal for ideas outside the scope of the project.
-->
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
* [x] This could be implemented without emitting different JS based on the types of the expressions
* [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
* [x] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).


## ⭐ Suggestion

Allow `export interface` and `export type` even when a TypeScript file already contains a `export =` statement.

<!-- A summary of what you'd like to see added or changed -->

## 📃 Motivating Example

Reference [this playground](https://www.typescriptlang.org/play?target=99&module=1&ts=4.6.0-dev.20220105#code/KYDwDg9gTgLgBAXjgcgLYQCYFcA2wB0oksAzsgNwBQlR08AlgHYzBQBmAhgMbBwDyYGPQiMScAN6U40uADcOOLMABccRllQAjVlQC+QA), TypeScript currently emits an error.

Previously the community heavily rely on `"esModuleInterop": true` to make CommonJS modules imported as expected in ESM, however with Node's native ESM resolution (`nodenext` module resolution), an `export default` is transpiled into `exports.default`, which can't be imported easily:

```ts
import fooExports from 'foo'; 

// Actually it is default.default
const foo = fooExports.default;
```

To get rid of this ugly and redundant usage, the community may use `export =` a much more than previous, but then we can't export types along with it.

<!--
  If you were announcing this feature in a blog post, what's a short explanation that shows
  a developer why this feature improves the language?
-->

## 💻 Use Cases

For any packages which want to compile into a `module.exports` but also export some types, this is a must have feature:

```ts
export interface Options {
  x: number;
  y: number;
}

export = function add({x, y}: Options) {
  return x + y;
};
```

<!--
  What do you want to use this for?
  What shortcomings exist with current approaches?
  What workarounds are you using in the meantime?
-->