From fa760967a293271d17f92c7790e8d4420460cec8 Mon Sep 17 00:00:00 2001 From: calebboyd Date: Fri, 2 Mar 2018 18:46:02 -0600 Subject: [PATCH] fix: use export = for typescript module definition --- package.json | 3 ++- types/index.d.ts | 42 ++++++++++++------------------------------ types/options.d.ts | 18 ++++++++++++++++++ types/test.ts | 9 +++++---- 4 files changed, 37 insertions(+), 35 deletions(-) create mode 100644 types/options.d.ts diff --git a/package.json b/package.json index 3edc94a..317cc71 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,8 @@ "files": [ "index.js", "templates.js", - "types/index.d.ts" + "types/index.d.ts", + "types/options.d.ts" ], "keywords": [ "color", diff --git a/types/index.d.ts b/types/index.d.ts index b4e4dc5..44d7154 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -1,36 +1,14 @@ -// Type definitions for Chalk -// Definitions by: Thomas Sauer - -export const enum Level { - None = 0, - Basic = 1, - Ansi256 = 2, - TrueColor = 3 +/// +interface ChalkConstructor { + new (options?: Chalk.Options): Chalk; + (options?: Chalk.Options): Chalk; } - -export interface ChalkOptions { - enabled?: boolean; - level?: Level; -} - -export interface ChalkConstructor { - new (options?: ChalkOptions): Chalk; - (options?: ChalkOptions): Chalk; -} - -export interface ColorSupport { - level: Level; - hasBasic: boolean; - has256: boolean; - has16m: boolean; -} - -export interface Chalk { +interface Chalk { (...text: string[]): string; (text: TemplateStringsArray, ...placeholders: string[]): string; constructor: ChalkConstructor; enabled: boolean; - level: Level; + level: Chalk.Level; rgb(r: number, g: number, b: number): this; hsl(h: number, s: number, l: number): this; hsv(h: number, s: number, v: number): this; @@ -92,6 +70,10 @@ export interface Chalk { readonly bgWhiteBright: this; } -declare const chalk: Chalk & { supportsColor: ColorSupport }; +interface chalk extends Chalk { + supportsColor: Chalk.ColorSupport; + default: chalk +} +declare const chalk: chalk +export = chalk -export default chalk diff --git a/types/options.d.ts b/types/options.d.ts new file mode 100644 index 0000000..3d4039a --- /dev/null +++ b/types/options.d.ts @@ -0,0 +1,18 @@ +declare namespace Chalk { + export const enum Level { + None = 0, + Basic = 1, + Ansi256 = 2, + TrueColor = 3 + } + export interface Options { + enabled?: boolean; + level?: Chalk.Level; + } + export interface ColorSupport { + level: Level; + hasBasic: boolean; + has256: boolean; + has16m: boolean; + } +} diff --git a/types/test.ts b/types/test.ts index cedb39a..1e1ce60 100644 --- a/types/test.ts +++ b/types/test.ts @@ -1,4 +1,5 @@ -import chalk, {Level} from '..'; +import chalk from '..' +import chalktr = require('..') chalk.underline('foo'); chalk.red('foo'); @@ -17,16 +18,16 @@ chalk.underline.red.bgGreen('foo'); chalk.grey('foo'); chalk.constructor({level: 1}); -const ctx = chalk.constructor({level: Level.TrueColor }); +const ctx = chalk.constructor({level: Chalk.Level.TrueColor }); ctx('foo'); ctx.red('foo'); ctx`foo`; chalk.enabled = true; chalk.level = 1; -chalk.level = Level.Ansi256; +chalk.level = Chalk.Level.Ansi256; -chalk.level === Level.Ansi256; +chalk.level === Chalk.Level.Ansi256; let chalkInstance = new chalk.constructor(); chalkInstance = chalk.constructor();