Skip to content

Commit

Permalink
Change tagged template literal argument type to accept unknown inst…
Browse files Browse the repository at this point in the history
…ead of just `string` (#316)
  • Loading branch information
vanbujm authored and sindresorhus committed Dec 28, 2018
1 parent 587a5fb commit 7f6e563
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 11 deletions.
4 changes: 2 additions & 2 deletions index.d.ts
Expand Up @@ -68,9 +68,9 @@ export interface ColorSupport {
}

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

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

/**
* Return a new Chalk instance.
Expand Down
2 changes: 1 addition & 1 deletion index.js.flow
Expand Up @@ -23,7 +23,7 @@ export type ColorSupport = {|

export interface Chalk {
(...text: string[]): string,
(text: TemplateStringsArray, ...placeholders: string[]): string,
(text: TemplateStringsArray, ...placeholders: mixed[]): string,
constructor(options?: Options): Chalk,
enabled: boolean,
level: Level,
Expand Down
1 change: 1 addition & 0 deletions index.test-d.ts
Expand Up @@ -27,6 +27,7 @@ expectType<Level>(chalk.level);
expectType<string>(chalk``);
const name = 'John';
expectType<string>(chalk`Hello {bold.red ${name}}`);
expectType<string>(chalk`Works with numbers {bold.red ${1}}`);

// -- Color methods --
expectType<colorReturn>(chalk.hex('#DEADED'));
Expand Down
8 changes: 0 additions & 8 deletions test/_flow.js
Expand Up @@ -9,10 +9,6 @@ chalk.constructor({level: 1});
new chalk.constructor({enabled: 'true'});
new chalk.constructor({enabled: true});

// $ExpectError (Can't pass in null)
chalk.underline(null);
chalk.underline('foo');

// $ExpectError (Can't have typo in chalk method)
chalk.rd('foo');
chalk.red('foo');
Expand All @@ -29,10 +25,6 @@ chalk.red.bgBlue.underline('foo');
const badCtx = chalk.constructor({level: 4});
const ctx = chalk.constructor({level: 3});

// $ExpectError (Can't pass in null)
ctx(null);
ctx('foo');

// $ExpectError (Can't have typo in method name)
ctx.gry('foo');
ctx.grey('foo');
Expand Down

0 comments on commit 7f6e563

Please sign in to comment.