diff --git a/index.d.ts b/index.d.ts index c7d4a54..4877f5e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -70,11 +70,11 @@ declare namespace chalk { has16m: boolean; } + type ChalkTemplateFunction = (text: TemplateStringsArray, ...placeholders: unknown[]) => string; + interface Chalk { (...text: unknown[]): string; - (text: TemplateStringsArray, ...placeholders: unknown[]): string; - /** Return a new Chalk instance. */ @@ -99,11 +99,9 @@ declare namespace chalk { @param color - Hexadecimal value representing the desired color. @example - ``` import chalk = require('chalk'); chalk.hex('#DEADED'); - ``` */ hex(color: string): this; @@ -113,11 +111,9 @@ declare namespace chalk { @param color - Keyword value representing the desired color. @example - ``` import chalk = require('chalk'); chalk.keyword('orange'); - ``` */ keyword(color: string): this; @@ -147,11 +143,9 @@ declare namespace chalk { @param color - Hexadecimal value representing the desired color. @example - ``` import chalk = require('chalk'); chalk.bgHex('#DEADED'); - ``` */ bgHex(color: string): this; @@ -161,11 +155,9 @@ declare namespace chalk { @param color - Keyword value representing the desired color. @example - ``` import chalk = require('chalk'); chalk.bgKeyword('orange'); - ``` */ bgKeyword(color: string): this; @@ -273,13 +265,15 @@ declare namespace chalk { } } +declare type NoThis = {[K in keyof T]: T[K] extends T ? T : T[K]}; + /** Main Chalk object that allows to chain styles together. Call the last one as a method with a string argument. Order doesn't matter, and later styles take precedent in case of a conflict. This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`. */ -declare const chalk: chalk.Chalk & { +declare const chalk: NoThis & chalk.ChalkTemplateFunction & { supportsColor: chalk.ColorSupport; Level: typeof LevelEnum; }; diff --git a/index.test-d.ts b/index.test-d.ts index 7a791a8..420cccd 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -2,7 +2,7 @@ import {expectType} from 'tsd'; import chalk = require('.'); // - Helpers - -type colorReturn = chalk.Chalk & {supportsColor: chalk.ColorSupport}; +type colorReturn = chalk.Chalk & {supportsColor?: never}; // - Level - expectType(chalk.Level.None);