Out-of-the-box TypeScript type errors
rendall opened this issue · comments
Using the latest commander.js with the latest typescript (and Node v18.12.1 FWIW), the Quick Start code from https://github.com/tj/commander.js/blob/HEAD/examples/string-util.js (but import via import { Command } from "commander";
)
Gets a squiggly line under program.parse() with
Expected 1 arguments, but got 0.ts(2554)
index.d.ts(208, 11): An argument for 'argv' was not provided.
(method) local.Command.parse(argv: string[]): local.Command
Parse argv, settings options and invoking commands when defined.
@param argv
@returns — for chaining
To replicate, create a new project as described above. For reference, here is the tsconfig I'm using:
{
"compilerOptions": {
"target": "es2016" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
"module": "Node16" /* Specify what module code is generated. */,
"rootDir": "./src" /* Specify the root folder within your source files. */,
"moduleResolution": "Node16" /* Specify how TypeScript looks up a file from a given module specifier. */,
"outDir": "./dist" /* Specify an output folder for all emitted files. */,
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
"strict": true /* Enable all strict type-checking options. */,
"skipLibCheck": true /* Skip type checking all .d.ts files. */
}
}
I was not able to reproduce this. I suspect TypeScript is finding an old version of the typings file, as local
has been gone for a while (#1081). If you are using npm, you can have a look at your Commander dependency using:
npm ls commander
The argument to .parse()
got made optional in #1172 which was released in Commander v5.
Ok. Might have been some version control weirdness. Let's close this.