Skip to content

Commit

Permalink
docs: Add TSDoc for TemplateStringsArray overload
Browse files Browse the repository at this point in the history
  • Loading branch information
ExE-Boss committed Apr 28, 2019
1 parent 1b168d4 commit f4f266d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
20 changes: 17 additions & 3 deletions index.d.ts
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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.Chalk> & chalk.ChalkTemplateFunction & {
declare const chalk: NoThis<chalk.Chalk> & chalk.ChalkFunction & {
supportsColor: chalk.ColorSupport;
Level: typeof LevelEnum;
};
Expand Down
5 changes: 4 additions & 1 deletion index.test-d.ts
@@ -1,4 +1,4 @@
import {expectType} from 'tsd';
import {expectType, expectError} from 'tsd';
import chalk = require('.');

// - Helpers -
Expand All @@ -15,6 +15,9 @@ expectType<boolean>(chalk.supportsColor.hasBasic);
expectType<boolean>(chalk.supportsColor.has256);
expectType<boolean>(chalk.supportsColor.has16m);

// -- `supportsColor` is not a member of the Chalk interface --
expectError(chalk.reset.supportsColor);

// - Chalk -
// -- Instance --
expectType<chalk.Chalk>(new chalk.Instance({level: 1}));
Expand Down

0 comments on commit f4f266d

Please sign in to comment.