1
我正在使用tsc -v 2.4.2
和Node v6.10.3来处理TypeScript中的一个小项目。TypeScript + NodeJS readline属性丢失
我想在CLI中捕获按键,所以我试图import * as readline from 'readline'
,然后用readline.emitKeyPressEvents(process.stdin)
,但它抱怨说the property emitKeyPressEvents is not found on typeof readline
。我也做过npm install --save @types/node
。
这里的一个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);
}
});
}
}
它花了一点今天发布的'@ types/node @ 8.0.36'包含'emitKeypressEvents'。 – Oblosys