简体   繁体   中英

How do I get intellisense to work with VS Code when writing Typescript with imported 3rd party JS modules?

I have the following import in my typescript file

import interactjs = require('http://cdnjs.cloudflare.com/ajax/libs/interact.js/1.2.6/interact.min.js');

I also have interact.d.ts in a relative path ../../../typings/interactjs/interact.d.js, how do I make typescript type check against the type declaration?

您必须在脚本文件中引用导入的定义文件:

/// <reference path="../../../typings/interactjs/interact.d.js" />

You can put your tsd files in jsconfig.json . See docs for details.

Summarized below for history and ease of reference.

With the introduction of jsconfig.json, you no longer need to use /// references in each file (these were required in the initial versions of VS Code). As the file set is defined in jsconfig.json, VS Code knows what files and symbols are part of your project.

As an example, you can just drop a new type definition .d.ts file into your project folder and VS Code will pick it up automatically.

{
  "files": [
      "app.js",
      "typings/node/dode.d.ts"
  ]
}

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM