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