Change tagged template literal argument type to accept unknown instead of just string (#316)

This commit is contained in:
Jonathan Van Buren 2018-12-28 19:13:56 +08:00 committed by Sindre Sorhus
parent 587a5fbcbb
commit 7f6e5630b0
4 changed files with 4 additions and 11 deletions

4
index.d.ts vendored
View file

@ -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.

View file

@ -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,

View file

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

View file

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