问题描述
我正在用 TypeScript 设置一个网络应用程序,但我似乎缺少一些我需要的基本类型.
I am setting a web app up in TypeScript and I seem to be missing some basic types I need.
当我编译 (npm run build
) 时,出现以下错误,
When I compile (npm run build
), I get the following errors,
错误 TS2304:找不到名称HTMLElement".
错误 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 类型的一部分,https://github.com/Microsoft/TypeScript/blob/master/lib/lib.es6.d.ts.
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 类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!