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 25, 2019
1 parent 7b9211b commit eec2982
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
9 changes: 6 additions & 3 deletions index.d.ts
Expand Up @@ -67,11 +67,11 @@ export interface ColorSupport {
has16m: boolean;
}

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

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

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

/**
* Return a new Chalk instance.
*/
Expand Down Expand Up @@ -265,12 +265,15 @@ export interface Chalk {
readonly bgWhiteBright: this;
}

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

/**
* 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 & {supportsColor: ColorSupport};
declare const chalk: NoThis<Chalk> & ChalkTemplateFunction & {readonly supportsColor: ColorSupport};

export default chalk;
4 changes: 2 additions & 2 deletions index.test-d.ts
@@ -1,8 +1,8 @@
import {expectType} from 'tsd-check';
import chalk, {Level, Chalk, ColorSupport} from '.';
import chalk, {Level, Chalk} from '.';

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

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

0 comments on commit eec2982

Please sign in to comment.