我不明白当我抽象options
到一个变量(甚至从另一个文件导入)时,Typescript 抱怨:
Argument of type '{ exclude: { type: string; required: boolean; description: string; default: never[]; alias: string; }; someOtherFlag: { type: string; required: boolean; description: string; default: never[]; }; }' is not assignable to parameter of type '{ [key: string]: Options; }'.
Property 'exclude' is incompatible with index signature.
Type '{ type: string; required: boolean; description: string; default: never[]; alias: string; }' is not assignable to type 'Options'.
Types of property 'type' are incompatible.
Type 'string' is not assignable to type '"string" | "number" | "boolean" | "array" | "count" | undefined'.ts(2345)
import * as yargs from 'yargs';
const options = {
exclude: {
type: 'array',
required: false,
description: 'Files to exclude',
default: [],
alias: 'e'
},
someOtherFlag: {
type: 'array',
required: false,
description: 'Another example flag'
default: []
}
};
// throws Typescript error
const cliOptions = yargs.options(options).argv;