docs: Add TSDoc for TemplateStringsArray overload
This commit is contained in:
parent
1b168d47db
commit
f4f266da7f
2 changed files with 21 additions and 4 deletions
20
index.d.ts
vendored
20
index.d.ts
vendored
|
|
@ -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;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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}));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue