unjs / consola

🐨 Elegant Console Logger for Node.js and Browser
Other
6.12k stars 175 forks source link

fix: correct and improve return types for single and multi select prompts #197

Closed DamianGlowala closed 1 year ago

codecov[bot] commented 1 year ago

Codecov Report

Merging #197 (ce769fa) into main (dabb705) will decrease coverage by 0.08%. The diff coverage is 0.00%.

:exclamation: Current head ce769fa differs from pull request most recent head 705ff8e. Consider uploading reports for the commit 705ff8e to get more accurate results

@@            Coverage Diff             @@
##             main     #197      +/-   ##
==========================================
- Coverage   62.24%   62.16%   -0.08%     
==========================================
  Files           9        9              
  Lines         792      793       +1     
  Branches       50       50              
==========================================
  Hits          493      493              
- Misses        299      300       +1     
Impacted Files Coverage Δ
src/consola.ts 62.98% <0.00%> (-0.16%) :arrow_down:
DamianGlowala commented 1 year ago

It would be great to be able to pass an optional generic for select and multiselect prompts to narrow down what type the options might be, e.g.:

type PackageManager = 'npm' | 'pnpm' | 'yarn'

await consola.prompt<PackageManager>(...)

giving us a more precise return type: Promise<PackageManager> (select) or Promise<PackageManager[]> (multiselect)

pi0 commented 1 year ago

It would be great to be able to pass an optional generic for select and multiselect prompts to narrow down what type the options might be, e.g.:

This is why we have two reserved positional generics. PR welcome to add 👍🏼