diff --git a/types/ansi/ansi-tests.ts b/types/ansi/ansi-tests.ts index 5d8e73e8ec..b2625defa5 100644 --- a/types/ansi/ansi-tests.ts +++ b/types/ansi/ansi-tests.ts @@ -20,5 +20,13 @@ Object.keys({ , brightCyan: 96 , brightWhite: 97 }).forEach((color) => { - cursor[color]().bold().write(`Hello, bold ${color.replace(/([a-z])([A-Z])/g, (_: string, l: string, u: string): string => `${l} ${u.toLowerCase()}`)} world!\n`).reset(); + const cname = color.replace(/([a-z])([A-Z])/g, (_: string, l: string, u: string): string => `${l} ${u.toLowerCase()}`); + + ((<(...anything: any[]) => ansi.Cursor> cursor[color])() + .bold() + .bg)[color === 'blue' || color === 'brightBlue' ? 'black' : 'blue']() + .write( + `Hello, bold ${cname} world!\n` + ) + .reset(); }); diff --git a/types/ansi/index.d.ts b/types/ansi/index.d.ts index 976268a29a..4e486d61ef 100644 --- a/types/ansi/index.d.ts +++ b/types/ansi/index.d.ts @@ -2,6 +2,7 @@ // Project: https://www.npmjs.com/package/ansi // Definitions by: Gustavo6046 // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.1 /** * References: @@ -14,11 +15,19 @@ /// import { Stream } from "stream"; -declare function ansi(stream: Stream, options?: any): ansi.Cursor; +interface CursorOptions { + enabled: boolean; + buffering: boolean; +} + +declare function ansi(stream: Stream, options?: CursorOptions): ansi.Cursor; declare namespace ansi { class Cursor { - constructor(stream: Stream, options?: any); + bg: Colorer; + fg: Colorer; + + constructor(stream: Stream, options?: CursorOptions); /** * Helper function that calls `write()` on the underlying Stream. @@ -161,7 +170,11 @@ declare namespace ansi { } interface Cursor { - [key: string]: (...anything: any[]) => Cursor; + [key: string]: ((...anything: any[]) => Cursor) | Colorer; + } + + interface Colorer { + [key: string]: (...anything: any[]) => (Cursor | Colorer); } }