AngiusA
Denoβ€’2y agoβ€’
1 reply
Angius

Typing `parseArgs` from `@std/cli` properly

I'm having trouble figuring out how would I type the result of parseArgs with collect setting.
import { parseArgs } from "@std/cli";

const args = parseArgs(Deno.args, { collect: ["path"] });

generatePaths(params[0].toString(), args["path"]);
                                    ^^^^^^^^^^^^

the error is caused by the function taking a { [key: string] string } as the second parameter, while args[path] is typed as unknown[].

The code works, just so we're clear, it's just the types that error out.
Was this page helpful?