打字稿错误:TS2304:找不到名字'$' [英] typescript error: TS2304: Cannot find name '$'

查看:169
本文介绍了打字稿错误:TS2304:找不到名字'$'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

声明

 x = $('#msgBox_' + scope.boxId).position().left;

生成


错误TS2304:找不到名称'$'

error TS2304: Cannot find name '$'

虽然 jquery @types 安装在node_modules文件夹中。

although jquery and @types are installed in the node_modules folder.

我的tsconfig.json看起来像这样:

My tsconfig.json looks like that:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "sourceMap": true,
    "moduleResolution": "node",
    "declaration": true
  },
  "exclude": [
    "node_modules"
  ]
}

我该如何解决这个问题?

How can I fix that?

推荐答案

原来我错过了@ types / jquery节点模块,其中包含$的定义。一旦我将@ types / jquery:^ 3.2.5添加到我的package.json中的devDependencies列表并通过npm install重新安装,一切正常。

Turns out I was missing the "@types/jquery" node module, which contains a definition of "$". Once I added "@types/jquery": "^3.2.5" to the list of "devDependencies" in my package.json and reinstalled via "npm install", everything worked fine.

这篇关于打字稿错误:TS2304:找不到名字'$'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆