Don't use `export default` in TypeScript

I was working on an npm package written in TypeScript. I anticipated that the package would be used by programmers using JavaScript and TypeScript. Using export default works fine in TypeScript. Consuming a default class looks like this:

1
2
import Trello from 'trello-helper'
const trello = new Trello()

The JavaScript users are not so lucky, they need to add a reference to the export named “default.”

1
2
const Trello = require("trello-helper");
const trello = new Trello.default();

This requirement strikes me as very non-intuitive for JavaScript users. Since the savings from using the default export is a pair of curly braces, and we’re all good at typing curly braces, I decided to no longer use export default in my code. That way the JavaScript import becomes the much more familiar:

1
2
const { Trello } = require("trello-helper");
const trello = new Trello();

In his stackoverflow answer to my question around the need for .default, Simon Chan pointed out a nice workaround. As nice as that workaround is, I think I’ll stick with not using export default.