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);