docs: Add TSDoc for TemplateStringsArray overload

This commit is contained in:
ExE Boss 2019-04-28 21:50:00 +02:00
parent 1b168d47db
commit f4f266da7f
No known key found for this signature in database
GPG key ID: BF4FA5DD733D8D1A
2 changed files with 21 additions and 4 deletions

20
index.d.ts vendored
View file

@ -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.Chalk> & chalk.ChalkTemplateFunction & {
declare const chalk: NoThis<chalk.Chalk> & chalk.ChalkFunction & {
supportsColor: chalk.ColorSupport;
Level: typeof LevelEnum;
};

View file

@ -1,4 +1,4 @@
import {expectType} from 'tsd';
import {expectType, expectError} from 'tsd';
import chalk = require('.');
// - Helpers -
@ -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}));