dsherret / dax

Cross-platform shell tools for Deno and Node.js inspired by zx.
MIT License
965 stars 33 forks source link

Strict typing for arguments #254

Closed naruaway closed 2 months ago

naruaway commented 3 months ago

IMHO, one of the strong benefit of using TypeScript for shell scripting is to get more static checks.

However, currently dax is using (strings: TemplateStringsArray, ...exprs: any[]): CommandBuilder type (source) for its primary API, which is $. Because of any in the type, we cannot detect incorrect arguments passed such as undefined or random incompatible objects.

import $ from 'dax-sh'

const myobj1 = {'hello': 'world'}
const myobj2 = undefined

// type check passes for the following, which is not desired.
await $`echo ${myobj1} ${myobj2}`

Proposed solution

I propose to stop using any in (strings: TemplateStringsArray, ...exprs: any[]): CommandBuilder by precisely model all the possible arguments.

Related issues

naruaway commented 2 months ago

Ok thanks, so the only way to emit error for the above case is to stop supporting objects with toString().... I think this is actually a good change but it is a breaking change 😢

I'll give up for now 👍