Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow export type along with export = statement #47455

Open
5 tasks done
otakustay opened this issue Jan 15, 2022 · 2 comments
Open
5 tasks done

Allow export type along with export = statement #47455

otakustay opened this issue Jan 15, 2022 · 2 comments
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript

Comments

@otakustay
Copy link

Suggestion

πŸ” Search Terms

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

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, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

Allow export interface and export type even when a TypeScript file already contains a export = statement.

πŸ“ƒ Motivating Example

Reference this playground, 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:

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.

πŸ’» Use Cases

For any packages which want to compile into a module.exports but also export some types, this is a must have feature:

export interface Options {
  x: number;
  y: number;
}

export = function add({x, y}: Options) {
  return x + y;
};
@xiaoxiangmoe
Copy link
Contributor

function add({ x, y }: add.Options) {
    return x + y;
}
namespace add {
    export interface Options {
        x: number;
        y: number;
    }
}

export = add;

@RyanCavanaugh RyanCavanaugh added Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript labels Jan 20, 2022
@bgmort
Copy link

bgmort commented Aug 4, 2023

I'll second this as a needed feature. I'm struggling to find the best way to create a well-typed and interoperable public interface for a package without it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting More Feedback This means we'd like to hear from more people who would be helped by this feature Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

4 participants