I'm quite new to TypeScript and am trying to script a little cli app.
I want to use npm~command-line-args but its definition is not available with typings
so I thought how hard could it be to create my own. Turns out it is harder than I expected.
So my goal is to export a module which exposes just a single function and maybe a small type declaration.
I tried this so far:
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[] ) {};
}
But am getting this error:
error TS1183: An implementation cannot be declared in ambient contexts.
Does:
export function commandLineArgs <R> ( optionDefinitions: cliOptionDefinition[] );
work the way that you would expect? (Omit the =
, and the {}
.) If you are intending to provide an implementation of commandLineArgs
, then you want to export it from a non-ambient (remove declare
etc.), preferably external, module (or, alternatively, namespace).
你应该看一下Polymer项目(例如polymer-cli ) - 他们使用带有Typescript的命令行参数。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.