Fix TypeScript types for supportsColor which is top‑level only (#342)
Co-Authored-By: Dimitri Benin <BendingBender@users.noreply.github.com>
This commit is contained in:
parent
d3be9c65b1
commit
b3e9b91405
2 changed files with 79 additions and 60 deletions
132
index.d.ts
vendored
132
index.d.ts
vendored
|
|
@ -70,11 +70,27 @@ declare namespace chalk {
|
||||||
has16m: boolean;
|
has16m: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Chalk {
|
interface ChalkFunction {
|
||||||
(...text: unknown[]): string;
|
/**
|
||||||
|
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;
|
(text: TemplateStringsArray, ...placeholders: unknown[]): string;
|
||||||
|
|
||||||
|
(...text: unknown[]): string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface Chalk extends ChalkFunction {
|
||||||
/**
|
/**
|
||||||
Return a new Chalk instance.
|
Return a new Chalk instance.
|
||||||
*/
|
*/
|
||||||
|
|
@ -105,7 +121,7 @@ declare namespace chalk {
|
||||||
chalk.hex('#DEADED');
|
chalk.hex('#DEADED');
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
hex(color: string): this;
|
hex(color: string): Chalk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Use keyword color value to set text color.
|
Use keyword color value to set text color.
|
||||||
|
|
@ -119,27 +135,27 @@ declare namespace chalk {
|
||||||
chalk.keyword('orange');
|
chalk.keyword('orange');
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
keyword(color: string): this;
|
keyword(color: string): Chalk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Use RGB values to set text color.
|
Use RGB values to set text color.
|
||||||
*/
|
*/
|
||||||
rgb(red: number, green: number, blue: number): this;
|
rgb(red: number, green: number, blue: number): Chalk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Use HSL values to set text color.
|
Use HSL values to set text color.
|
||||||
*/
|
*/
|
||||||
hsl(hue: number, saturation: number, lightness: number): this;
|
hsl(hue: number, saturation: number, lightness: number): Chalk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Use HSV values to set text color.
|
Use HSV values to set text color.
|
||||||
*/
|
*/
|
||||||
hsv(hue: number, saturation: number, value: number): this;
|
hsv(hue: number, saturation: number, value: number): Chalk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Use HWB values to set text color.
|
Use HWB values to set text color.
|
||||||
*/
|
*/
|
||||||
hwb(hue: number, whiteness: number, blackness: number): this;
|
hwb(hue: number, whiteness: number, blackness: number): Chalk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Use HEX value to set background color.
|
Use HEX value to set background color.
|
||||||
|
|
@ -153,7 +169,7 @@ declare namespace chalk {
|
||||||
chalk.bgHex('#DEADED');
|
chalk.bgHex('#DEADED');
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
bgHex(color: string): this;
|
bgHex(color: string): Chalk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Use keyword color value to set background color.
|
Use keyword color value to set background color.
|
||||||
|
|
@ -167,109 +183,109 @@ declare namespace chalk {
|
||||||
chalk.bgKeyword('orange');
|
chalk.bgKeyword('orange');
|
||||||
```
|
```
|
||||||
*/
|
*/
|
||||||
bgKeyword(color: string): this;
|
bgKeyword(color: string): Chalk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Use RGB values to set background color.
|
Use RGB values to set background color.
|
||||||
*/
|
*/
|
||||||
bgRgb(red: number, green: number, blue: number): this;
|
bgRgb(red: number, green: number, blue: number): Chalk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Use HSL values to set background color.
|
Use HSL values to set background color.
|
||||||
*/
|
*/
|
||||||
bgHsl(hue: number, saturation: number, lightness: number): this;
|
bgHsl(hue: number, saturation: number, lightness: number): Chalk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Use HSV values to set background color.
|
Use HSV values to set background color.
|
||||||
*/
|
*/
|
||||||
bgHsv(hue: number, saturation: number, value: number): this;
|
bgHsv(hue: number, saturation: number, value: number): Chalk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Use HWB values to set background color.
|
Use HWB values to set background color.
|
||||||
*/
|
*/
|
||||||
bgHwb(hue: number, whiteness: number, blackness: number): this;
|
bgHwb(hue: number, whiteness: number, blackness: number): Chalk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Modifier: Resets the current color chain.
|
Modifier: Resets the current color chain.
|
||||||
*/
|
*/
|
||||||
readonly reset: this;
|
readonly reset: Chalk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Modifier: Make text bold.
|
Modifier: Make text bold.
|
||||||
*/
|
*/
|
||||||
readonly bold: this;
|
readonly bold: Chalk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Modifier: Emitting only a small amount of light.
|
Modifier: Emitting only a small amount of light.
|
||||||
*/
|
*/
|
||||||
readonly dim: this;
|
readonly dim: Chalk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Modifier: Make text italic. (Not widely supported)
|
Modifier: Make text italic. (Not widely supported)
|
||||||
*/
|
*/
|
||||||
readonly italic: this;
|
readonly italic: Chalk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Modifier: Make text underline. (Not widely supported)
|
Modifier: Make text underline. (Not widely supported)
|
||||||
*/
|
*/
|
||||||
readonly underline: this;
|
readonly underline: Chalk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Modifier: Inverse background and foreground colors.
|
Modifier: Inverse background and foreground colors.
|
||||||
*/
|
*/
|
||||||
readonly inverse: this;
|
readonly inverse: Chalk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Modifier: Prints the text, but makes it invisible.
|
Modifier: Prints the text, but makes it invisible.
|
||||||
*/
|
*/
|
||||||
readonly hidden: this;
|
readonly hidden: Chalk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Modifier: Puts a horizontal line through the center of the text. (Not widely supported)
|
Modifier: Puts a horizontal line through the center of the text. (Not widely supported)
|
||||||
*/
|
*/
|
||||||
readonly strikethrough: this;
|
readonly strikethrough: Chalk;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Modifier: Prints the text only when Chalk is enabled.
|
Modifier: Prints the text only when Chalk is enabled.
|
||||||
Can be useful for things that are purely cosmetic.
|
Can be useful for things that are purely cosmetic.
|
||||||
*/
|
*/
|
||||||
readonly visible: this;
|
readonly visible: Chalk;
|
||||||
|
|
||||||
readonly black: this;
|
readonly black: Chalk;
|
||||||
readonly red: this;
|
readonly red: Chalk;
|
||||||
readonly green: this;
|
readonly green: Chalk;
|
||||||
readonly yellow: this;
|
readonly yellow: Chalk;
|
||||||
readonly blue: this;
|
readonly blue: Chalk;
|
||||||
readonly magenta: this;
|
readonly magenta: Chalk;
|
||||||
readonly cyan: this;
|
readonly cyan: Chalk;
|
||||||
readonly white: this;
|
readonly white: Chalk;
|
||||||
readonly gray: this;
|
readonly gray: Chalk;
|
||||||
readonly grey: this;
|
readonly grey: Chalk;
|
||||||
readonly blackBright: this;
|
readonly blackBright: Chalk;
|
||||||
readonly redBright: this;
|
readonly redBright: Chalk;
|
||||||
readonly greenBright: this;
|
readonly greenBright: Chalk;
|
||||||
readonly yellowBright: this;
|
readonly yellowBright: Chalk;
|
||||||
readonly blueBright: this;
|
readonly blueBright: Chalk;
|
||||||
readonly magentaBright: this;
|
readonly magentaBright: Chalk;
|
||||||
readonly cyanBright: this;
|
readonly cyanBright: Chalk;
|
||||||
readonly whiteBright: this;
|
readonly whiteBright: Chalk;
|
||||||
|
|
||||||
readonly bgBlack: this;
|
readonly bgBlack: Chalk;
|
||||||
readonly bgRed: this;
|
readonly bgRed: Chalk;
|
||||||
readonly bgGreen: this;
|
readonly bgGreen: Chalk;
|
||||||
readonly bgYellow: this;
|
readonly bgYellow: Chalk;
|
||||||
readonly bgBlue: this;
|
readonly bgBlue: Chalk;
|
||||||
readonly bgMagenta: this;
|
readonly bgMagenta: Chalk;
|
||||||
readonly bgCyan: this;
|
readonly bgCyan: Chalk;
|
||||||
readonly bgWhite: this;
|
readonly bgWhite: Chalk;
|
||||||
readonly bgBlackBright: this;
|
readonly bgBlackBright: Chalk;
|
||||||
readonly bgRedBright: this;
|
readonly bgRedBright: Chalk;
|
||||||
readonly bgGreenBright: this;
|
readonly bgGreenBright: Chalk;
|
||||||
readonly bgYellowBright: this;
|
readonly bgYellowBright: Chalk;
|
||||||
readonly bgBlueBright: this;
|
readonly bgBlueBright: Chalk;
|
||||||
readonly bgMagentaBright: this;
|
readonly bgMagentaBright: Chalk;
|
||||||
readonly bgCyanBright: this;
|
readonly bgCyanBright: Chalk;
|
||||||
readonly bgWhiteBright: this;
|
readonly bgWhiteBright: Chalk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -279,7 +295,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.
|
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`.
|
This simply means that `chalk.red.yellow.green` is equivalent to `chalk.green`.
|
||||||
*/
|
*/
|
||||||
declare const chalk: chalk.Chalk & {
|
declare const chalk: chalk.Chalk & chalk.ChalkFunction & {
|
||||||
supportsColor: chalk.ColorSupport;
|
supportsColor: chalk.ColorSupport;
|
||||||
Level: typeof LevelEnum;
|
Level: typeof LevelEnum;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import {expectType} from 'tsd';
|
import {expectType, expectError} from 'tsd';
|
||||||
import chalk = require('.');
|
import chalk = require('.');
|
||||||
|
|
||||||
// - Helpers -
|
// - Helpers -
|
||||||
type colorReturn = chalk.Chalk & {supportsColor: chalk.ColorSupport};
|
type colorReturn = chalk.Chalk & {supportsColor?: never};
|
||||||
|
|
||||||
// - Level -
|
// - Level -
|
||||||
expectType<number>(chalk.Level.None);
|
expectType<number>(chalk.Level.None);
|
||||||
|
|
@ -15,6 +15,9 @@ expectType<boolean>(chalk.supportsColor.hasBasic);
|
||||||
expectType<boolean>(chalk.supportsColor.has256);
|
expectType<boolean>(chalk.supportsColor.has256);
|
||||||
expectType<boolean>(chalk.supportsColor.has16m);
|
expectType<boolean>(chalk.supportsColor.has16m);
|
||||||
|
|
||||||
|
// -- `supportsColor` is not a member of the Chalk interface --
|
||||||
|
expectError(chalk.reset.supportsColor);
|
||||||
|
|
||||||
// - Chalk -
|
// - Chalk -
|
||||||
// -- Instance --
|
// -- Instance --
|
||||||
expectType<chalk.Chalk>(new chalk.Instance({level: 1}));
|
expectType<chalk.Chalk>(new chalk.Instance({level: 1}));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue