From eec2982a942a80ff9d3ecbf2209067486b611b4c Mon Sep 17 00:00:00 2001 From: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> Date: Thu, 25 Apr 2019 22:10:00 +0200 Subject: [PATCH] =?UTF-8?q?fix(types):=20`supportsColor`=20is=C2=A0top?= =?UTF-8?q?=E2=80=91level=20only?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.d.ts | 9 ++++++--- index.test-d.ts | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/index.d.ts b/index.d.ts index 6256ce36..580ced2d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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. */ @@ -265,12 +265,15 @@ export interface Chalk { readonly bgWhiteBright: this; } +declare type NoThis = {[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 & ChalkTemplateFunction & {readonly supportsColor: ColorSupport}; export default chalk; diff --git a/index.test-d.ts b/index.test-d.ts index 0b26e9c5..5ed3052f 100644 --- a/index.test-d.ts +++ b/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(Level.None);