我对TypeScript很陌生,正在尝试编写一个小的cli应用程序。声明TypeScript中的节点模块,在打字时不可用
我想使用npm〜命令行参数,但其定义不适用于typings
,因此我认为创建自己的程序有多难。原来,这比我想象的要难。
所以我的目标是导出一个模块,它只公开一个函数,也许是一个小型的声明。
我想这个至今:
declare module 'command-line-args' {
export interface cliOptionDefinition {
name: string,
alias?: string,
type: BooleanConstructor|StringConstructor|NumberConstructor,
multiple?: Boolean,
defaultOption?: any
}
export = function commandLineArgs <R> (optionDefinitions: cliOptionDefinition[]) {};
}
,但我得到这个错误:
error TS1183: An implementation cannot be declared in ambient contexts.
我想,在模块声明中。但是这导致了一个错误的编译js文件,它是这样的:'const command_line_args_1 = require('command-line-args');/* ... */const options = command_line_args_1.commandLineArgs(optionDefinitions);' – lumio