fix(types): add better descriptions for event emitter methods (#6417)

This commit is contained in:
Joel Einbinder 2021-07-08 11:24:46 -05:00 committed by GitHub
parent ae489b1c43
commit e4698b5f6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 129 additions and 515 deletions

633
types/types.d.ts vendored

File diff suppressed because it is too large Load Diff

View File

@ -220,10 +220,17 @@ function createEventDescriptions(classDesc) {
function classBody(classDesc) {
const parts = [];
const eventDescriptions = createEventDescriptions(classDesc);
const commentForMethod = {
off: 'Removes and event listener added by `on` or `addListener`',
removeListener: 'Removes and event listener added by `on` or `addListener`',
once: 'Adds an event listener that will be automatically removed after it is triggered once. See `addListener` for more information about this event.'
}
for (const method of ['on', 'once', 'addListener', 'removeListener', 'off']) {
for (const {eventName, params, comment} of eventDescriptions) {
if (comment)
if ((method === 'on' || method === 'addListener') && comment)
parts.push(writeComment(comment, ' '));
else
parts.push(writeComment(commentForMethod[method], ' '));
parts.push(` ${method}(event: '${eventName}', listener: (${params}) => void): this;\n`);
}
}
@ -434,4 +441,4 @@ function renderJSSignature(args) {
if (hasOptional)
tokens.push(']');
return tokens.join('');
}
}