0

I'm working on a new nodejs 5.10.1 project using typescript.

I have tsc installed version 1.8.9

I created a new project that contains the following configuration files:

package.json

{
  "name": "mdb-analyze",
  "version": "1.0.0",
  "description": "",
  "main": "mdb-analyze.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "command-line-args": "^2.1.6"
  }
}

tsconfig.json

{
    "compilerOptions": {
        "module": "commonjs",
        "target": "es6",
        "noImplicitAny": false,
        "sourceMap": false
    },
    "exclude": [
        "node_modules"
    ]
}

typings.json

{
  "name": "mdb-analyze",
  "version": false,
  "dependencies": {}
}

and this is my main mdb-analyze.ts file:

import * as commandLineArgs from 'command-line-args';

var cli = commandLineArgs([
  { name: 'verbose', alias: 'v', type: Boolean },
  { name: 'fjso', alias:'f',type: String, multiple: true, defaultOption: true },
  { name: 'help',alias:'h',type:Boolean }
])

var params = cli.parse();
if (params.help || !params.fjso || params.fjso.length == 0) {
    console.info(cli.getUsage());
} else {

}

when I try to compile with tsc i get the following error:

mdb-analyze.ts(5,34): error TS2307: Cannot find module 'command-line-args'.

welp i've been told to use typings to load typescript definitions for the modules i want. but searching on typings doesn't show this module. i'm new to typescript, and very confused on what to do next.

any information regarding the issue would be greatly appreciated.

4

1 回答 1

2

If there are no typings available you can write your own d.ts files containing necessary type declarations.

There are some samples for you: link, link

Hope this helps.

于 2016-04-12T09:36:08.843 回答