Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support boolean and array types #92

Open
timdeschryver opened this issue Jan 2, 2025 · 0 comments
Open

Support boolean and array types #92

timdeschryver opened this issue Jan 2, 2025 · 0 comments

Comments

@timdeschryver
Copy link

👋 Hello, first of all happy new year! 🥳
After migrating a couple projects from chalk to picocolors I've stumbled upon the same issue in some migrations in TypeScript projects.

With chalk it's possible to pass all types compared to picocolors, this because chalk doesn't put any constrains to the input arguments.

https://github.com/chalk/chalk/blob/5dbc1e2633f3874f43c144fa4919934bc934c495/source/index.d.ts#L33

Picocolors only accepts the following types, string | number | null | undefined.

export type Formatter = (input: string | number | null | undefined) => string

Example (https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAYwBYEMA2BrOAzKERwDky6GhA3AFCiSxxjAIQ54GENNNrQDOFllAPSC4Ad2gYelJgDseENAFMAdNwDmAChKZlaqIsUyNMKAFdFASgtVZ8paoibtGZQBNQG7Oh6Xr0iHIKKupaqDoARmjmGgDaXmg+ADRwJuYAulZUQiIwAJ5gigC0ilB4UP6B9iEcELr6hsZmvjYBdsGOGjVuHvE+mRVtDppdkdFx3orJqYoZ1kA):

import chalk from 'chalk';
import pico from 'picocolors';

// works
console.log(chalk.green(true));
console.log(chalk.dim(false));
console.log(chalk.blue([false, true]));

// type-error
console.log(pico.green(true));
console.log(pico.dim(false));
console.log(pico.blue([false, true]));

I like that this is more type-safe, on the other hand it makes it less developer friendly.
That's why I propose to expand the types to all primitive types (and arrays of primitive types).

If accepted I can create a PR with the change.
This change will only update the types, the runtime behavior remains the same because it works already as expected.

@timdeschryver timdeschryver changed the title boolean and array types Support boolean and array types Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant