From 98c9f30fc39e375ab07e4ebbd0a7a55f150d8e72 Mon Sep 17 00:00:00 2001 From: Joshua Ball Date: Sat, 11 Mar 2017 11:10:23 -0800 Subject: [PATCH] AsyncCompleter for readline Previous Completer interface required implementation of BOTH types (sync and async). Sync type could be assigned to async type, but not vice versa, forcing implementers to always implement the sync interface. --- node/index.d.ts | 10 ++++------ node/node-tests.ts | 6 ++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/node/index.d.ts b/node/index.d.ts index ca6e83a267..55f1fd947f 100644 --- a/node/index.d.ts +++ b/node/index.d.ts @@ -1546,22 +1546,20 @@ declare module "readline" { prependOnceListener(event: "SIGTSTP", listener: () => void): this; } - export interface Completer { - (line: string): CompleterResult; - (line: string, callback: (err: any, result: CompleterResult) => void): any; - } + type Completer = (line: string) => CompleterResult; + type AsyncCompleter = (line: string, callback: (err: any, result: CompleterResult) => void) => any; export type CompleterResult = [string[], string]; export interface ReadLineOptions { input: NodeJS.ReadableStream; output?: NodeJS.WritableStream; - completer?: Completer; + completer?: Completer | AsyncCompleter; terminal?: boolean; historySize?: number; } - export function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer, terminal?: boolean): ReadLine; + export function createInterface(input: NodeJS.ReadableStream, output?: NodeJS.WritableStream, completer?: Completer | AsyncCompleter, terminal?: boolean): ReadLine; export function createInterface(options: ReadLineOptions): ReadLine; export function cursorTo(stream: NodeJS.WritableStream, x: number, y: number): void; diff --git a/node/node-tests.ts b/node/node-tests.ts index 04166bc006..325b95f266 100644 --- a/node/node-tests.ts +++ b/node/node-tests.ts @@ -1265,6 +1265,12 @@ namespace readline_tests { return [['test'], 'test']; } }); + result = readline.createInterface({ + input: input, + completer: function(str: string, callback: (err: any, result: readline.CompleterResult) => void): any { + callback(null, [['test'], 'test']); + } + }); } {