除非在每个文件中引用,否则无法在TS文件中找到名称"$"

sta*_*gt3 18 typescript visual-studio-2015

我在Visual Studio 2015中设置了打字稿.我将使用带有TS文件的jquery.当我使用jquery时,VS会强调'$'并说无法找到名称,并且无法成功构建.它构建的唯一方法是在每个TS文件中添加对jquery typings的引用./// <reference path="typings/index.d.ts" /> 无论如何全局使用此引用而不是将其添加到每个文件?

在Visual Studio Code中我没有这个问题.

我的目录看起来像这样-scripts --ts --- typings --- main.ts tsconfig.json --js

我的tasks.json文件在root中

    {
    "version": "0.1.0",

    // The command is tsc. Assumes that tsc has been installed using npm install -g typescript
    "command": "tsc",

    // The command is a shell script
    "isShellCommand": true,

    // Show the output window only if unrecognized errors occur.
    "showOutput": "silent",

    // Tell the tsc compiler to use the tsconfig.json from the open folder.
    "args": ["-p", "../Scripts/Weblink/ts"],

    // use the standard tsc problem matcher to find compile problems
    // in the output.
    "problemMatcher": "$tsc"
}
Run Code Online (Sandbox Code Playgroud)

脚本/ ts中的taskconfig.json

{
"compileOnSave": true,
"compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "outDir": "../lib/"
},
"exclude": [
    "typings/*"
]
}
Run Code Online (Sandbox Code Playgroud)

len*_*nny 32

在TypeScript 2.x中,你应该安装这样的类型:

npm install --save @types/jquery

然后:

import * as $ from "jquery";

无需引用它,TypeScript将自动处理它.

更多信息