2017-09-13 4 views
1

tsc -v 2.4.2 및 노드 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을 작성했습니다.

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); 
      } 
     }); 
    } 
} 

답변

2

있어서 실제로 node typings 누락되어

여기서 M (N)은 WE이다. 정확한 이름은 실제로는 emitKeypressEvents (소문자는 p)이지만 그 중 하나도 누락되었습니다. 나는 이것이 단순한 감시라고 가정하므로 DefinitelyTyped에 추가로 PR을 제출했습니다. (다 잘만 경우, 일주일에 주위)이 처리하는 데 시간이 걸릴 수 있지만 그 동안 당신은 InputManager가 포함 된 파일에 로컬 선언을 추가하여 코드를 확인 입력 할 수 있습니다 : 그것은 조금했다

declare module 'readline' { 
    export function emitKeypressEvents(stream: NodeJS.ReadableStream, interface?: ReadLine): void; 
} 
+0

평소보다 길지만'@ types/node @ 8.0.36'에는'emitKeypressEvents'가 포함되어 있습니다. – Oblosys

관련 문제