Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 找不到名称'$';在TS文件中,除非在每个文件中引用_Typescript_Visual Studio 2015 - Fatal编程技术网

Typescript 找不到名称'$';在TS文件中,除非在每个文件中引用

Typescript 找不到名称'$';在TS文件中,除非在每个文件中引用,typescript,visual-studio-2015,Typescript,Visual Studio 2015,我正在Visual Studio 2015中设置typescript。我将在TS文件中使用jquery。当我使用jquery时,VS将在“$”下面加下划线,并说找不到名称,并且无法成功构建。构建它的唯一方法是在每个TS文件中添加对jquery类型的引用//是否可以全局使用此引用,而不是将其添加到每个文件中 在VisualStudio代码中,我没有这个问题 我的目录是这样的 -剧本 --ts ---打字 ---梅因酒店 tsconfig.json --js 根目录中的My tasks.json文件

我正在Visual Studio 2015中设置typescript。我将在TS文件中使用jquery。当我使用jquery时,VS将在“$”下面加下划线,并说找不到名称,并且无法成功构建。构建它的唯一方法是在每个TS文件中添加对jquery类型的引用<代码>//是否可以全局使用此引用,而不是将其添加到每个文件中

在VisualStudio代码中,我没有这个问题

我的目录是这样的 -剧本 --ts ---打字 ---梅因酒店 tsconfig.json --js

根目录中的My tasks.json文件

    {
    "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"
}

脚本/ts中的taskconfig.json

{
"compileOnSave": true,
"compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5",
    "outDir": "../lib/"
},
"exclude": [
    "typings/*"
]
}

在TypeScript 2.x中,您应该像这样安装打字:

npm安装--save@types/jquery

然后:

import*作为$from“jquery”

不需要引用它,TypeScript将自动处理它


添加到tsconfig.json:

"moduleResolution": "node",
"lib": [ "es2015", "es2017", "dom" ]
  • 在使用npm的TypeScript 3中:

    npm安装--保存dev@types/jquery

    以及:

    导入“jquery”

    别名不是必需的

  • 如果不使用npm:

    添加一个新的声明(jquery.d.ts)文件,其中包含
    声明模块'jquery'

    以及:

    导入“jquery”


您使用的是哪一版本的typescript?最新版本2.1.4与typescript中的VS文件一起安装,而不是nodery来指定tsconfig.json中的引用。谢谢,它现在已成功构建,但VS仍然在$下面加下划线,无论出于何种原因,都会出现相同的错误,并且任何插件都应该在该文件中,因此,编译器将这些签名合并到已知的jquery typings接口中。对性能、捆绑包的大小等是否有任何影响。。。或者,如果用“jquery”
中的“
import*as$”替换它们,我无法想象会发生什么事情?