小编Mor*_*ndo的帖子

缺少 TypeScript + NodeJS readline 属性

我正在使用 TypeScripttsc -v 2.4.2和 Node v6.10.3开发一个小项目。

我想在 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) => …
Run Code Online (Sandbox Code Playgroud)

readline node.js typescript

5
推荐指数
1
解决办法
3401
查看次数

标签 统计

node.js ×1

readline ×1

typescript ×1