问题描述
我正在使用TypeScript设置一个Web应用程序,我似乎缺少一些我需要的基本类型。
I am setting a web app up in TypeScript and I seem to be missing some basic types I need.
当我编译时( npm运行构建
),我得到以下错误,
When I compile (npm run build
), I get the following errors,
错误TS2304:找不到名称'SVGElement'。
error TS2304: Cannot find name 'SVGElement'.
错误TS2304:找不到名称'EventTarget'。
error TS2304: Cannot find name 'EventTarget'.
错误TS2304:找不到名称'TouchEvent'。
error TS2304: Cannot find name 'TouchEvent'.
错误TS2304:找不到名称'MouseEvent'。
error TS2304: Cannot find name 'MouseEvent'.
错误TS2304:找不到名称'PointerEvent'。
error TS2304: Cannot find name 'PointerEvent'.
基于我的谷歌搜索我假设我在项目设置中缺少基本的东西。看起来这些类型只是假设在那里有Typescript。
Based on my Googling I assuming I am missing something basic in my project setup. It seems like these types are just assumed to be there with Typescript.
编辑:特别是它应该是ES6类型的一部分,。
Specially it should be part of the ES6 types, https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es6.d.ts.
这是我的 package.json
文件:
{
"name": "wip",
"version": "1.0.0",
"description": "",
"main": "index.html",
"dependencies": {
"hammerjs": "2.0.8"
},
"devDependencies": {
"@types/chai": "3.4.35",
"@types/mocha": "2.2.39",
"@types/node": "7.0.5",
"@types/hammerjs": "2.0.34",
"chai": "3.5.0",
"mocha": "3.2.0",
"safe-mock": "0.2.0",
"ts-node": "2.1.0",
"tslint": "4.5.1",
"typescript": "2.2.1",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.4.1"
},
"scripts": {
"test": "mocha test --require ts-node/register test/**/*.ts && npm run build",
"dev": "webpack-dev-server --watch --content-base . -d --progress",
"build": "tsc"
},
"author": "",
"license": "ISC"
}
有什么建议吗?
推荐答案
尝试将以下 lib
部分添加到 tsconfig.json
文件中。
Try adding the following lib
section to your tsconfig.json
file.
{
"compilerOptions": {
"lib": [
"es2016",
"dom"
]
}
}
这篇关于缺少TypeScript项目中的基本DOM类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!