Having trouble building an old typescript project. Unable to build an old project that I am coming back to. There is an issue with q when trying to build. I assume it is my tsc version, but every version I have tried results in errors.
There were some suggestions online to change the typescript version to past 2.2 because it handles typings differently, but nothing has resulted in any progress.
I have provided error information, and versions. Also my tsconfig.json. Please let me know if you need more information.
Errors ($tsc -v 2.1.5)
$ tsc -p ./
typings/modules/q/index.d.ts(10,1): error TS1316: Global module exports may only appear at top level.
Versions
nvm: 1.1.5
npm: 4.1.2
tsc: 2.1.5
node: 7.5.0
$ npm list --depth=0
+-- @types/q@1.5.1
`-- typescript@2.1.5
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "amd",
"outDir": "static/js",
"sourceMap": true,
"strictNullChecks": true,
"noImplicitAny": true
},
"files": [
"typings/index.d.ts",
"../common/types.d.ts"
],
"include": [
"src/**/*.ts"
]
}
EDIT
The errors listed under tsc v2.3.0 were actually still 2.1.5. I didn't install typepscript globally, so it was still using 2.1.5 instead of 2.3.0 when I ran the tsc command.
答案 0 :(得分:1)
当声明文件中出现错误时,通常表明声明文件使用的语法在您的TypeScript版本中不可用。
在这种情况下,让我们看一下报告为错误的行。
64: then<U = T, V = never>(onFulfill?: ...
200: thenReject<U = T>(reason?: any): Promise<U>;
此处报告的错误指向类型实参部分中的等号。这表明不支持默认类型参数。由于在TS2.3中添加了对default type arguments的支持,因此这实际上没有任何意义。我最好的猜测是您实际上没有为这些错误安装2.3,并且版本已切换...
请牢记,其他错误可能是由于旧的typings
文件和新的@types
文件(<2.1,如果我没记错的话)之间的不兼容所致。使用node_modules/@types/q
中安装的类型,您无需包括自定义的typings
文件夹,因此您应该能够删除typings/modules/q
(实际上,整个typings
文件夹)来解决其他错误。
如果这不能解决您的问题,那么通过克隆项目可以更轻松地找出问题所在。