From f6b0e45cdd84a664b6fe69d40f2009413902897c Mon Sep 17 00:00:00 2001 From: calebboyd Date: Wed, 18 Oct 2017 23:16:54 -0500 Subject: [PATCH] fix(types): change overload order for better implicit any inference --- types/index.d.ts | 24 +++++++++++++++--------- types/test.ts | 3 +++ 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/types/index.d.ts b/types/index.d.ts index 3908a1b..eac5837 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -13,20 +13,26 @@ export interface ChalkOptions { level?: Level; } -export interface Chalk { +export interface ChalkConstructor extends Chalk { new (options?: ChalkOptions): Chalk; (options?: ChalkOptions): Chalk; +} + +export interface ColorSupport { + level: Level; + hasBasic: boolean; + has256: boolean; + has16m: boolean; +} + +export interface Chalk { (...text: string[]): string; (text: TemplateStringsArray, ...placeholders: string[]): string; - constructor: Chalk; + new (options?: ChalkOptions): Chalk; + (options: ChalkOptions): Chalk; + constructor: ChalkConstructor; enabled: boolean; level: Level; - supportsColor: { - level: Level; - hasBasic: boolean; - has256: boolean; - has16m: boolean; - }; rgb(r: number, g: number, b: number): Chalk; hsl(h: number, s: number, l: number): Chalk; hsv(h: number, s: number, v: number): Chalk; @@ -86,6 +92,6 @@ export interface Chalk { bgWhiteBright: Chalk; } -declare const chalk: Chalk +declare const chalk: Chalk & { supportsColor: ColorSupport }; export default chalk diff --git a/types/test.ts b/types/test.ts index 01509fd..16652ee 100644 --- a/types/test.ts +++ b/types/test.ts @@ -32,6 +32,9 @@ let chalkInstance = new chalk(); chalkInstance = new chalk.constructor(); chalkInstance = chalk.constructor(); +let x = 'imastring'; +x = chalk(); + chalk.enabled; chalk.level; chalk.supportsColor.level;