Skip to content

Commit

Permalink
fix(types): supportsColor is top‑level only
Browse files Browse the repository at this point in the history
  • Loading branch information
ExE-Boss committed Apr 28, 2019
1 parent 98628d9 commit 1b168d4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
16 changes: 5 additions & 11 deletions index.d.ts
Expand Up @@ -70,11 +70,11 @@ declare namespace chalk {
has16m: boolean;
}

type ChalkTemplateFunction = (text: TemplateStringsArray, ...placeholders: unknown[]) => string;

interface Chalk {
(...text: unknown[]): string;

(text: TemplateStringsArray, ...placeholders: unknown[]): string;

/**
Return a new Chalk instance.
*/
Expand All @@ -99,11 +99,9 @@ declare namespace chalk {
@param color - Hexadecimal value representing the desired color.
@example
```
import chalk = require('chalk');
chalk.hex('#DEADED');
```
*/
hex(color: string): this;

Expand All @@ -113,11 +111,9 @@ declare namespace chalk {
@param color - Keyword value representing the desired color.
@example
```
import chalk = require('chalk');
chalk.keyword('orange');
```
*/
keyword(color: string): this;

Expand Down Expand Up @@ -147,11 +143,9 @@ declare namespace chalk {
@param color - Hexadecimal value representing the desired color.
@example
```
import chalk = require('chalk');
chalk.bgHex('#DEADED');
```
*/
bgHex(color: string): this;

Expand All @@ -161,11 +155,9 @@ declare namespace chalk {
@param color - Keyword value representing the desired color.
@example
```
import chalk = require('chalk');
chalk.bgKeyword('orange');
```
*/
bgKeyword(color: string): this;

Expand Down Expand Up @@ -273,13 +265,15 @@ declare namespace chalk {
}
}

declare type NoThis<T> = {[K in keyof T]: T[K] extends T ? T : T[K]};

/**
Main Chalk object that allows to chain styles together.
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: chalk.Chalk & {
declare const chalk: NoThis<chalk.Chalk> & chalk.ChalkTemplateFunction & {
supportsColor: chalk.ColorSupport;
Level: typeof LevelEnum;
};
Expand Down
2 changes: 1 addition & 1 deletion index.test-d.ts
Expand Up @@ -2,7 +2,7 @@ import {expectType} from 'tsd';
import chalk = require('.');

// - Helpers -
type colorReturn = chalk.Chalk & {supportsColor: chalk.ColorSupport};
type colorReturn = chalk.Chalk & {supportsColor?: never};

// - Level -
expectType<number>(chalk.Level.None);
Expand Down

0 comments on commit 1b168d4

Please sign in to comment.