scottcorgan / tiny-emitter

A tiny (less than 1k) event emitter library
MIT License
935 stars 67 forks source link

TinyEmitter can't be imported in TypeScript with the normal module import syntax #29

Closed MadaraUchiha closed 6 years ago

MadaraUchiha commented 6 years ago

Code:

import * as TinyEmitter from 'tiny-emitter';

Expected: TinyEmitter available and no compilation errors thrown

Actual: TypeScript complains about module 'tiny-emitter' resolves to a non-module entity and cannot be imported using this construct


Classes can't be exported with the export = Something syntax and be imported with the import * as syntax.

They must be imported with import TinyEmitter = require('tiny-emitter'), which will also fail compilation if you're not targeting commonjs modules.

While the correct solution is likely to move to ES2015 modules in the package's source (and have the transpiler deal with it), I propose we add either a exports.default = TinyEmitter or exports.TinyEmitter = TinyEmitter and change the .d.ts file, so that we may import TinyEmitter in the standard way.

scottcorgan commented 6 years ago

I personally don't use TypeScript, but I'd like to get this resolved (as I thought https://github.com/scottcorgan/tiny-emitter/pull/22 fixed it). I'm open to a PR to fix it, and that'd be awesome!

danguilherme commented 5 years ago

Is there any reason why this fix was not published to npm?

scottcorgan commented 5 years ago

@danguilherme it is now! Sorry for that.

danguilherme commented 5 years ago

Awesome, thanks! I think you might want to create a tag for that? 😄

scottcorgan commented 5 years ago

Done