Angius
Angius
DDeno
Created by Angius on 7/30/2024 in #help
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"]);
^^^^^^^^^^^^
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.
2 replies