I'm working on a small project in TypeScript with tsc -v 2.4.2 and Node v6.10.3.
I would like to capture keypresses in the CLI, so I tried to import * as readline from 'readline' and then later use readline.emitKeyPressEvents(process.stdin), but it complains that the property emitKeyPressEvents is not found on typeof readline.
I have also done npm install --save @types/node.
Here's a M(N)WE:
import * as readline from "readline";
import {SIGINT} from "constants";
export class InputManager
{
private _currentStates: Array<IKeyEntity>;
private _oldStates: Array<IKeyEntity>;
public constructor()
{
// Throws error, won't compile
readline.emitKeyPressEvents(process.stdin);
}
public handleInput()
{
if (process.stdin.isTTY)
process.stdin.setRawMode(true);
process.stdin.on('keypress', (str: string, key: any) => {
process.stdout.write('Handling keypress ['+str+']');
if (key && key.ctrl && (key.name == 'c' || key.name == 'l'))
{
process.kill(process.pid, SIGINT);
}
});
}
}