node.js - TypeScript + NodeJS readline property missing -
i'm working on small project in typescript tsc -v 2.4.2
, node v6.10.3.
i capture keypresses in cli, tried import * readline 'readline'
, later use readline.emitkeypressevents(process.stdin)
, complains the property emitkeypressevents not found on typeof readline
.
i have done npm install --save @types/node
.
here's m(n)we:
import * readline "readline"; import {sigint} "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); } }); } }
the method indeed missing node
typings. correct name emitkeypressevents
(with lower-case p
), 1 missing. assume simple oversight, i've submitted pr addition definitelytyped. might take while process (around week, if goes well), in mean time can type check code adding local declaration file containing inputmanager
:
declare module 'readline' { export function emitkeypressevents(stream: nodejs.readablestream, interface?: readline): void; }
Comments
Post a Comment