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

Strict typing for arguments #254

Closed
naruaway opened this issue Mar 24, 2024 · 1 comment · Fixed by #259
Closed

Strict typing for arguments #254

naruaway opened this issue Mar 24, 2024 · 1 comment · Fixed by #259

Comments

@naruaway
Copy link

naruaway commented Mar 24, 2024

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
Copy link
Author

naruaway commented Apr 7, 2024

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 👍

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

Successfully merging a pull request may close this issue.

1 participant