andreypopp / autobind-decorator

Decorator to automatically bind methods to class instances

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Default export gets overwritten in generated code (breaks usage with TypeScript)

pelotom opened this issue · comments

In the current build of the library, at the top of the file we have

exports['default'] = autobind;

but then at the end we have

module.exports = exports['default'];

The latter wipes out the former, eliminating the default export. It probably usually goes unnoticed because with Babel, a default import falls back to importing the entire module, so

import autobind from 'autobind-decorator'

becomes the same as

import * as autobind from 'autobind-decorator'

Unfortunately TypeScript is less forgiving, requiring you to get the default import vs import * right, and as a result this package doesn't work out of the box with typescript. It also seems impossible to assign a functional type to an import *, which is what we need to do in this case. So, long story short, I think the solution is to upgrade Babel so the default export works as expected.

@bradleyayers how does our build work with babel 5 modules? Do we need to do anything once this uses babel6?

In our project TypeScript targets ES6, and webpack does the ES6→ES5 conversion and takes responsibility for the fuzzy default imports. Nothing will change for us.