chore: migrate src/Input to typescript (#5710)

* chore: migrate src/Input to typescript

This moves `Keyboard`, `Mouse` and `Touchscreen` to TypeScript. We gain
some nice TS benefits here; by creating a type for all the keycodes we
support we can type the input args as that rather than `string` which
will hopefully save some users some debugging once we ship our TS types
in a future version.

* Remove from externs file

* Update utils/doclint/check_public_api/index.js

Co-Authored-By: Mathias Bynens <mathias@qiwi.be>

Co-authored-by: Mathias Bynens <mathias@qiwi.be>
This commit is contained in:
Jack Franklin
2020-04-22 15:44:04 +01:00
committed by GitHub
parent 11bc5a6450
commit 133abb07cf
6 changed files with 103 additions and 100 deletions

View File

@@ -184,6 +184,15 @@ function checkSources(sources) {
return new Documentation.Type(typeName, []);
}
/**
* @param {!ts.Symbol} symbol
* @return {boolean}
*/
function symbolHasPrivateModifier(symbol) {
const modifiers = symbol.valueDeclaration.modifiers || [];
return modifiers.some(modifier => modifier.kind === ts.SyntaxKind.PrivateKeyword);
}
/**
* @param {string} className
* @param {!ts.Symbol} symbol
@@ -194,8 +203,14 @@ function checkSources(sources) {
const members = classEvents.get(className) || [];
for (const [name, member] of symbol.members || []) {
if (name.startsWith('_'))
/* Before TypeScript we denoted private methods with an underscore
* but in TypeScript we use the private keyword
* hence we check for either here.
*/
if (name.startsWith('_') || symbolHasPrivateModifier(member))
continue;
const memberType = checker.getTypeOfSymbolAtLocation(member, member.valueDeclaration);
const signature = memberType.getCallSignatures()[0];
if (signature)