Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeScript types for supportsColor which is top‑level only #342

Merged
merged 4 commits into from May 11, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
```
sindresorhus marked this conversation as resolved.
Show resolved Hide resolved
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]};
ExE-Boss marked this conversation as resolved.
Show resolved Hide resolved

/**
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