TooTallNate / node-speaker

Output PCM audio data to the speakers
648 stars 145 forks source link

Inconsistencies between declared TypeScript export and actual export #127

Closed fwcd closed 5 years ago

fwcd commented 5 years ago

The TypeScript declaration file declares Speaker as a default export:

https://github.com/TooTallNate/node-speaker/blob/f365fc8b84c0a856c1bdc71255da01d7aee6ac02/index.d.ts#L20-L27

If that was the case, Speaker could be imported with the following syntax:

import Speaker from "speaker";

This does not work, however, since the actual file does not assign exports.default, but rather exports:

https://github.com/TooTallNate/node-speaker/blob/f365fc8b84c0a856c1bdc71255da01d7aee6ac02/index.js#L353-L357

The correct way to import Speaker would be to use

import * as Speaker from "speaker";

...which yields the following (incorrect) error by the compiler though:

src/output/SpeakerOutput.ts:6:19 - error TS2709: Cannot use namespace
'Speaker' as a type.

6  private speaker: Speaker;
                    ~~~~~~~
9       this.speaker = new Speaker(options);
                       ~~~~~~~~~~~~~~~~~~~~
LinusU commented 5 years ago

I think that #128 should be the correct way to declare this, could you try and see that it works for you?

btw, the correct way to import this module should be import Speaker = require('speaker') unless you are using synthetic es module imports...

fwcd commented 5 years ago
import Speaker from "speaker";

seems to work fine, thanks!