Skip to content

Commit

Permalink
TypeScript fixes (#217)
Browse files Browse the repository at this point in the history
  • Loading branch information
calebboyd authored and sindresorhus committed Oct 24, 2017
1 parent e1177ec commit 7be154c
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 67 deletions.
135 changes: 70 additions & 65 deletions types/index.d.ts
Expand Up @@ -13,80 +13,85 @@ export interface ChalkOptions {
level?: Level;
}

export interface Chalk {
export interface ChalkConstructor {
new (options?: ChalkOptions): Chalk;
(options?: ChalkOptions): Chalk;
}

export interface ColorSupport {
level: Level;
hasBasic: boolean;
has256: boolean;
has16m: boolean;
}

export interface Chalk {
(...text: string[]): string;
(text: TemplateStringsArray, ...placeholders: string[]): string;
constructor: Chalk;
constructor: ChalkConstructor;
enabled: boolean;
level: Level;
supportsColor: {
level: Level;
hasBasic: boolean;
has256: boolean;
has16m: boolean;
};
rgb(r: number, g: number, b: number): Chalk;
hsl(h: number, s: number, l: number): Chalk;
hsv(h: number, s: number, v: number): Chalk;
hwb(h: number, w: number, b: number): Chalk;
bgHex(color: string): Chalk;
bgKeyword(color: string): Chalk;
bgRgb(r: number, g: number, b: number): Chalk;
bgHsl(h: number, s: number, l: number): Chalk;
bgHsv(h: number, s: number, v: number): Chalk;
bgHwb(h: number, w: number, b: number): Chalk;
hex(color: string): Chalk;
keyword(color: string): Chalk;
rgb(r: number, g: number, b: number): this;
hsl(h: number, s: number, l: number): this;
hsv(h: number, s: number, v: number): this;
hwb(h: number, w: number, b: number): this;
bgHex(color: string): this;
bgKeyword(color: string): this;
bgRgb(r: number, g: number, b: number): this;
bgHsl(h: number, s: number, l: number): this;
bgHsv(h: number, s: number, v: number): this;
bgHwb(h: number, w: number, b: number): this;
hex(color: string): this;
keyword(color: string): this;

reset: Chalk;
bold: Chalk;
dim: Chalk;
italic: Chalk;
underline: Chalk;
inverse: Chalk;
hidden: Chalk;
strikethrough: Chalk;
readonly reset: this;
readonly bold: this;
readonly dim: this;
readonly italic: this;
readonly underline: this;
readonly inverse: this;
readonly hidden: this;
readonly strikethrough: this;

visible: Chalk;
readonly visible: this;

black: Chalk;
red: Chalk;
green: Chalk;
yellow: Chalk;
blue: Chalk;
magenta: Chalk;
cyan: Chalk;
white: Chalk;
gray: Chalk;
grey: Chalk;
blackBright: Chalk;
redBright: Chalk;
greenBright: Chalk;
yellowBright: Chalk;
blueBright: Chalk;
magentaBright: Chalk;
cyanBright: Chalk;
whiteBright: Chalk;
readonly black: this;
readonly red: this;
readonly green: this;
readonly yellow: this;
readonly blue: this;
readonly magenta: this;
readonly cyan: this;
readonly white: this;
readonly gray: this;
readonly grey: this;
readonly blackBright: this;
readonly redBright: this;
readonly greenBright: this;
readonly yellowBright: this;
readonly blueBright: this;
readonly magentaBright: this;
readonly cyanBright: this;
readonly whiteBright: this;

bgBlack: Chalk;
bgRed: Chalk;
bgGreen: Chalk;
bgYellow: Chalk;
bgBlue: Chalk;
bgMagenta: Chalk;
bgCyan: Chalk;
bgWhite: Chalk;
bgBlackBright: Chalk;
bgRedBright: Chalk;
bgGreenBright: Chalk;
bgYellowBright: Chalk;
bgBlueBright: Chalk;
bgMagentaBright: Chalk;
bgCyanBright: Chalk;
bgWhiteBright: Chalk;
readonly bgBlack: this;
readonly bgRed: this;
readonly bgGreen: this;
readonly bgYellow: this;
readonly bgBlue: this;
readonly bgMagenta: this;
readonly bgCyan: this;
readonly bgWhite: this;
readonly bgBlackBright: this;
readonly bgRedBright: this;
readonly bgGreenBright: this;
readonly bgYellowBright: this;
readonly bgBlueBright: this;
readonly bgMagentaBright: this;
readonly bgCyanBright: this;
readonly bgWhiteBright: this;
}

declare function chalk (): any;
export default chalk as Chalk;
declare const chalk: Chalk & { supportsColor: ColorSupport };

export default chalk
9 changes: 7 additions & 2 deletions types/test.ts
Expand Up @@ -28,10 +28,15 @@ chalk.level = Level.Ansi256;

chalk.level === Level.Ansi256;

let chalkInstance = new chalk();
chalkInstance = new chalk.constructor();
let chalkInstance = new chalk.constructor();
chalkInstance = chalk.constructor();

chalkInstance.blue('foo');
chalkInstance`foo`;

let x = 'imastring';
x = chalk();

chalk.enabled;
chalk.level;
chalk.supportsColor.level;
Expand Down

0 comments on commit 7be154c

Please sign in to comment.