typescriptUsingTsConfig在我的项目中不起作用

时间:2017-07-20 01:18:12

标签: visual-studio angular typescript gruntjs

我正在我的gruntfile.js中执行以下grunt任务:

    'typescriptUsingTsConfig': {
        'basic': {
            'options': {
                'rootDir': './ng2'
            }
        }
    }

我从另一个成功运行任务的项目中复制了此任务。当我运行这个任务时,我得到了

这篇文章底部的错误。为该项目安装了2.4.0版本的typescript。我是

不确定这里缺少什么。

=============================================== ================================================== ===

C:\CODE\Test\src\Test.Website> cmd.exe /c grunt -b "C:\CODE\Test\src\Test.Website" --gruntfile "C:

\CODE\Test\src\Test.Website\Gruntfile.js" typescriptUsingTsConfig --color
Running "typescriptUsingTsConfig:basic" (typescriptUsingTsConfig) task
Running C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Web\External\Node.exe C:

\CODE\Test\src\Test.Website\node_modules\typescript\bin\tsc --project ./ng2
Warning: ng2/app.module.ts(1,21): error TS6053: File 

'C:/CODE/Test/src/Test.Website/typings/globals/core-js/index.d.ts' not found.
ng2/services/user.service.ts(37,16): error TS2693: 'Promise' only refers to a type, but is being used 

as a value here.
node_modules/@angular/common/src/directives/ng_class.d.ts(48,34): error TS2304: Cannot find name 

'Set'.
node_modules/@angular/compiler/src/aot/compiler.d.ts(56,32): error TS2304: Cannot find name 'Map'.
node_modules/@angular/compiler/src/compile_metadata.d.ts(369,20): error TS2304: Cannot find name 

'Set'.
node_modules/@angular/compiler/src/compile_metadata.d.ts(371,28): error TS2304: Cannot find name 

'Set'.
node_modules/@angular/compiler/src/compile_metadata.d.ts(373,15): error TS2304: Cannot find name 

'Set'.
node_modules/@angular/compiler/src/compile_metadata.d.ts(375,23): error TS2304: Cannot find name 

'Set'.
node_modules/@angular/compiler/src/compile_metadata.d.ts(377,17): error TS2304: Cannot find name 

'Set'.
node_modules/@angular/compiler/src/compile_metadata.d.ts(379,25): error TS2304: Cannot find name 

'Set'.
node_modules/@angular/compiler/src/output/output_ast.d.ts(458,63): error TS2304: Cannot find name 

'Set'.
node_modules/@angular/core/src/change_detection/differs/default_iterable_differ.d.ts(28,32): error 

TS2304: Cannot find name 'Iterable'.
node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts(24,16): error 

TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts(32,16): error 

TS2304: Cannot find name 'Map'.
node_modules/@angular/core/src/change_detection/differs/iterable_differs.d.ts(15,48): error TS2304: 

Cannot find name 'Iterable'.
node_modules/@angular/core/src/change_detection/differs/keyvalue_differs.d.ts(23,18): error TS2304: 

Cannot find name 'Map'.
node_modules/@angular/core/src/di/reflective_provider.d.ts(87,123): error TS2304: Cannot find name 

'Map'.
node_modules/@angular/core/src/di/reflective_provider.d.ts(87,165): error TS2304: Cannot find name 

'Map'.
node_modules/@angular/http/src/headers.d.ts(52,71): error TS2304: Cannot find name 'Map'.
node_modules/@angular/http/src/url_search_params.d.ts(46,16): error TS2304: Cannot find name 'Map'.
node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(79,33): error TS2304: Cannot 

find name 'Map'.
node_modules/@angular/platform-browser/src/dom/dom_adapter.d.ts(97,42): error TS2304: Cannot find name 

'Map'.
node_modules/@angular/platform-browser/src/dom/shared_styles_host.d.ts(11,30): error TS2304: Cannot 

find name 'Set'.
node_modules/@angular/platform-browser/src/dom/shared_styles_host.d.ts(22,30): error TS2304: Cannot 

find name 'Set'.
node_modules/@angular/router/src/router_outlet_context.d.ts(42,28): error TS2304: Cannot find name 

'Map'.
node_modules/@angular/router/src/router_outlet_context.d.ts(43,34): error TS2304: Cannot find name 

'Map'.
node_modules/rxjs/Observable.d.ts(68,60): error TS2693: 'Promise' only refers to a type, but is being 

used as a value here.
node_modules/rxjs/Subject.d.ts(16,22): error TS2415: Class 'Subject<T>' incorrectly extends base class 

'Observable<T>'.
  Types of property 'lift' are incompatible.
    Type '<R>(operator: Operator<T, R>) => Observable<T>' is not assignable to type '<R>(operator: 

Operator<T, R>) => Observable<R>'.
      Type 'Observable<T>' is not assignable to type 'Observable<R>'.
        Type 'T' is not assignable to type 'R'.
node_modules/rxjs/operator/toPromise.d.ts(3,79): error TS2693: 'Promise' only refers to a type, but is 

being used as a value here. Use --force to continue.
Aborted due to warnings.
Process terminated with code 1.

更新

我根据对此主题的反馈更新了我的设置,但现在收到以下错误:

C:\CODE\Test.Web.Benport\src\Test.Web.Website> cmd.exe /c grunt -b "C:\CODE\Test.Web.Benport\src\Test.Web.Website" --gruntfile "C:\CODE\Test.Web.Benport\src\Test.Web.Website\Gruntfile.js" typescriptUsingTsConfig --color
Running "typescriptUsingTsConfig:basic" (typescriptUsingTsConfig) task
Running C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Web\External\Node.exe C:\CODE\Test.Web.Benport\src\Test.Web.Website\node_modules\typescript\bin\tsc --project ./ng2
Warning: node_modules/typescript/lib/lib.es2015.collection.d.ts(45,11): error TS2428: All declarations of 'WeakMap' must have identical type parameters.
node_modules/typescript/lib/lib.es2015.core.d.ts(21,14): error TS2300: Duplicate identifier 'PropertyKey'.
node_modules/typescript/lib/lib.es2015.iterable.d.ts(124,11): error TS2428: All declarations of 'WeakMap' must have identical type parameters.
node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts(133,11): error TS2428: All declarations of 'WeakMap' must have identical type parameters.
typings/globals/core-js/index.d.ts(3,14): error TS2300: Duplicate identifier 'PropertyKey'.
typings/globals/core-js/index.d.ts(67,5): error TS2687: All declarations of 'name' must have identical modifiers.
typings/globals/core-js/index.d.ts(127,5): error TS2403: Subsequent variable declarations must have the same type.  Variable '[Symbol.unscopables]' must be of type '{ copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: ...', but here has type 'any'.
typings/globals/core-js/index.d.ts(244,5): error TS2687: All declarations of 'flags' must have identical modifiers.
typings/globals/core-js/index.d.ts(258,5): error TS2687: All declarations of 'EPSILON' must have identical modifiers.
typings/globals/core-js/index.d.ts(293,5): error TS2687: All declarations of 'MAX_SAFE_INTEGER' must have identical modifiers.
typings/globals/core-js/index.d.ts(300,5): error TS2687: All declarations of 'MIN_SAFE_INTEGER' must have identical modifiers.
typings/globals/core-js/index.d.ts(439,5): error TS2403: Subsequent variable declarations must have the same type.  Variable '[Symbol.toStringTag]' must be of type '"Symbol"', but here has type 'string'.
typings/globals/core-js/index.d.ts(439,5): error TS2687: All declarations of '[Symbol.toStringTag]' must have identical modifiers.
typings/globals/core-js/index.d.ts(446,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
typings/globals/core-js/index.d.ts(474,5): error TS2687: All declarations of 'hasInstance' must have identical modifiers.
typings/globals/core-js/index.d.ts(480,5): error TS2687: All declarations of 'isConcatSpreadable' must have identical modifiers.
typings/globals/core-js/index.d.ts(486,5): error TS2687: All declarations of 'iterator' must have identical modifiers.
typings/globals/core-js/index.d.ts(492,5): error TS2687: All declarations of 'match' must have identical modifiers.
typings/globals/core-js/index.d.ts(498,5): error TS2687: All declarations of 'replace' must have identical modifiers.
typings/globals/core-js/index.d.ts(504,5): error TS2687: All declarations of 'search' must have identical modifiers.
typings/globals/core-js/index.d.ts(510,5): error TS2687: All declarations of 'species' must have identical modifiers.
typings/globals/core-js/index.d.ts(516,5): error TS2687: All declarations of 'split' must have identical modifiers.
typings/globals/core-js/index.d.ts(522,5): error TS2687: All declarations of 'toPrimitive' must have identical modifiers.
typings/globals/core-js/index.d.ts(528,5): error TS2687: All declarations of 'toStringTag' must have identical modifiers.
typings/globals/core-js/index.d.ts(534,5): error TS2687: All declarations of 'unscopables' must have identical modifiers.
typings/globals/core-js/index.d.ts(591,5): error TS2403: Subsequent variable declarations must have the same type.  Variable '[Symbol.toStringTag]' must be of type '"Math"', but here has type 'string'.
typings/globals/core-js/index.d.ts(591,5): error TS2687: All declarations of '[Symbol.toStringTag]' must have identical modifiers.
typings/globals/core-js/index.d.ts(595,5): error TS2403: Subsequent variable declarations must have the same type.  Variable '[Symbol.toStringTag]' must be of type '"JSON"', but here has type 'string'.
typings/globals/core-js/index.d.ts(595,5): error TS2687: All declarations of '[Symbol.toStringTag]' must have identical modifiers.
typings/globals/core-js/index.d.ts(610,5): error TS2687: All declarations of 'size' must have identical modifiers.
typings/globals/core-js/index.d.ts(616,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
typings/globals/core-js/index.d.ts(627,5): error TS2687: All declarations of 'size' must have identical modifiers.
typings/globals/core-js/index.d.ts(633,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
typings/globals/core-js/index.d.ts(638,11): error TS2428: All declarations of 'WeakMap' must have identical type parameters.
typings/globals/core-js/index.d.ts(646,27): error TS2344: Type 'K' does not satisfy the constraint 'object'.
typings/globals/core-js/index.d.ts(647,53): error TS2344: Type 'K' does not satisfy the constraint 'object'.
typings/globals/core-js/index.d.ts(648,5): error TS2403: Subsequent variable declarations must have the same type.  Variable 'prototype' must be of type 'WeakMap<object, any>', but here has type 'WeakMap<any, any>'.
typings/globals/core-js/index.d.ts(648,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
typings/globals/core-js/index.d.ts(662,5): error TS2403: Subsequent variable declarations must have the same type.  Variable 'prototype' must be of type 'WeakSet<object>', but here has type 'WeakSet<any>'.
typings/globals/core-js/index.d.ts(662,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
typings/globals/core-js/index.d.ts(674,5): error TS2687: All declarations of 'value' must have identical modifiers.
typings/globals/core-js/index.d.ts(786,5): error TS2687: All declarations of 'prototype' must have identical modifiers. Use --force to continue.
Aborted due to warnings.
Process terminated with code 1.

1 个答案:

答案 0 :(得分:0)

好的,所以错误正是它所说的:

  

&#39; C:/CODE/Test/src/Test.Website/typings/globals/core-js/index.d.ts'未找到。   ng2 / services / user.service.ts(37,16):错误TS2693:&#39;承诺&#39;仅指一种类型,但正在使用

缺少声明文件。我与Grunt的TypeScript配置并不相似,因为我已经使用了大约3年,但这是我推荐的。

运行

typings uninstall --save core-js

然后运行

npm uninstall --save @types/core-js

以防万一。

然后在你的tsconfig文件中,更改或设置`&#34; compilerOptions&#34;的"lib"选项。财产如下

{
  "compilerOptions": {
    "lib": ["dom", "es2015"],
    // whatever else you had previously
  }
}

最后,您可能需要添加the declaration I suggest in this answer才能解决上一个错误(rxjs / Subject的错误)

此外,如果您对为什么感到好奇,核心j的声明会导致这些问题read my answer to a related question