-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Fails to generate typescript declarations from JS when extending EventEmitter #42405
Comments
@weswigham seems WAI-ish, but is there anything more clever that could be done? |
Considering the TS equivalent, import { EventEmitter } from 'events'
class Manager extends EventEmitter {
constructor () {
super()
}
}
export = Manager works fine, and that JS should be bound pretty similarly to the above TS now, I'm thinking it's probably a bug somewhere in JS declaration binding. |
What happens if: import internal = require('events');
namespace EventEmitter {
// Should just be `export { EventEmitter }`, but that doesn't work in TypeScript 3.4
export { internal as EventEmitter };
} in namespace EventEmitter {
// Note that this only works from TypeScript 3.5 onwards:
export { EventEmitter };
} Also, I can’t reproduce this on TypeScript 4.1. |
Yeah, after looking at it, @ExE-Boss is right - this was fixed in 4.1. Check out the repro: // @allowJs: true
// @checkJs: true
// @outDir: ./out
// @declaration: true
// @filename: node_modules/@types/node/index.d.ts
declare module "events" {
import internal = require('events');
class EventEmitter {
member(): void;
}
namespace EventEmitter {
// Should just be `export { EventEmitter }`, but that doesn't work in TypeScript 3.4
export { internal as EventEmitter };
}
export = EventEmitter;
}
// @filename: file.js
/// <reference types="node" />
const { EventEmitter } = require('events')
class Manager extends EventEmitter {
constructor () {
super()
}
}
module.exports = Manager So, good news OP! It already works in 4.1 and above! |
Bug Report
🔎 Search Terms
🕗 Version & Regression Information
[email protected]
This happened from 15th, more precisely after DefinitelyTyped/DefinitelyTyped#50266 being merged and released.
⏯ Playground Link
I believe I cannot add JS here 😞
You can look into
libp2p
before this PR being merged libp2p/js-libp2p#846.Commit hash to use: d19401aa4cafcf2237af90b677c743b0ff0f871e. Just need
npm i && npm run build
💻 Code
🙁 Actual behavior
Cannot generate typescript declaration file with errors like:
🙂 Expected behavior
Does not fail to build and generate the declaration files.
The text was updated successfully, but these errors were encountered: