diff --git a/index.d.ts b/index.d.ts index 4877f5e0..92f37f1e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -70,11 +70,25 @@ declare namespace chalk { has16m: boolean; } - type ChalkTemplateFunction = (text: TemplateStringsArray, ...placeholders: unknown[]) => string; + interface ChalkFunction { + /** + Use a template string. + + @remarks Template literals are unsupported for nested calls (see [issue #341](https://github.com/chalk/chalk/issues/341)) + + @example + log(chalk` + CPU: {red ${cpu.totalPercent}%} + RAM: {green ${ram.used / ram.total * 100}%} + DISK: {rgb(255,131,0) ${disk.used / disk.total * 100}%} + `); + */ + (text: TemplateStringsArray, ...placeholders: unknown[]): string; - interface Chalk { (...text: unknown[]): string; + } + interface Chalk extends ChalkFunction { /** Return a new Chalk instance. */ @@ -273,7 +287,7 @@ 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: NoThis & chalk.ChalkTemplateFunction & { +declare const chalk: NoThis & chalk.ChalkFunction & { supportsColor: chalk.ColorSupport; Level: typeof LevelEnum; }; diff --git a/index.test-d.ts b/index.test-d.ts index 420cccd1..5068d33a 100644 --- a/index.test-d.ts +++ b/index.test-d.ts @@ -1,4 +1,4 @@ -import {expectType} from 'tsd'; +import {expectType, expectError} from 'tsd'; import chalk = require('.'); // - Helpers - @@ -15,6 +15,9 @@ expectType(chalk.supportsColor.hasBasic); expectType(chalk.supportsColor.has256); expectType(chalk.supportsColor.has16m); +// -- `supportsColor` is noy a member of the Chalk interface -- +expectError(chalk.reset.supportsColor); + // - Chalk - // -- Instance -- expectType(new chalk.Instance({level: 1}));