【问题标题】:Various Typescript Errors in Angular2 Node Modules after adding Exclude添加排除后Angular2节点模块中的各种打字稿错误
【发布时间】:2016-08-08 02:25:40
【问题描述】:

这是我当前的 tsconfig.json。

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": false,
    "outDir": "./dist"
  },
  "exclude": [
    "bower_components",
    "node_modules",
    "typings/main",
    "typings/main.d.ts"
  ]
}

当我在 exclude 下添加 typings 条目时,我得到了各种构建错误。

错误 TS2304 构建:找不到名称“区域”。

错误 TS2305 构建:模块 '".../wwwroot/node_modules/angular2/src/core/linker/interfaces"' 有 没有导出成员“LIFECYCLE_HOOKS_VALUES”。

错误 TS2339 构建:类型上不存在属性“hostBoundary” '注射器'。

错误 TS2415 构建:“MockDirectiveResolver”类错误扩展 基类“DirectiveResolver”。

错误 TS4058 构建:导出函数的返回类型已经或正在使用 来自外部模块的名称“ComponentRef” “.../wwwroot/node_modules/angular2/src/core/linker/dynamic_component_loader” 但不能命名。

Angular2/Typescript 的正确 tsconfig 设置是什么?

其中许多也来自示例或测试文件夹。我可以删除它们吗?

更新

这是我的网络项目文件中的内容。

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
  </PropertyGroup>
  <Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
  <PropertyGroup Label="Globals">
    <ProjectGuid>3775534b-d08c-45f2-8d5a-4a4f6e91edb9</ProjectGuid>
    <RootNamespace>MyProject</RootNamespace>
    <BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
    <OutputPath Condition="'$(OutputPath)'=='' ">..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
    <SccProjectName>SAK</SccProjectName>
    <SccProvider>SAK</SccProvider>
    <SccAuxPath>SAK</SccAuxPath>
    <SccLocalPath>SAK</SccLocalPath>
  </PropertyGroup>
  <PropertyGroup>
    <SchemaVersion>2.0</SchemaVersion>
  </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
    <TypeScriptTarget>ES5</TypeScriptTarget>
    <TypeScriptJSXEmit>None</TypeScriptJSXEmit>
    <TypeScriptCompileOnSaveEnabled>True</TypeScriptCompileOnSaveEnabled>
    <TypeScriptNoImplicitAny>False</TypeScriptNoImplicitAny>
    <TypeScriptModuleKind>CommonJS</TypeScriptModuleKind>
    <TypeScriptRemoveComments>False</TypeScriptRemoveComments>
    <TypeScriptOutFile />
    <TypeScriptModuleResolution>NodeJs</TypeScriptModuleResolution>
    <TypeScriptOutDir />
    <TypeScriptGeneratesDeclarations>False</TypeScriptGeneratesDeclarations>
    <TypeScriptNoEmitOnError>True</TypeScriptNoEmitOnError>
    <TypeScriptSourceMap>True</TypeScriptSourceMap>
    <TypeScriptMapRoot />
    <TypeScriptSourceRoot />
    <TypeScriptExperimentalDecorators>True</TypeScriptExperimentalDecorators>
  </PropertyGroup>
  <Target Name="FixTsBuildConfiguration" BeforeTargets="CompileTypeScript" >
    <PropertyGroup>
      <TypeScriptBuildConfigurations>$(TypeScriptBuildConfigurations.Replace("--moduleResolution NodeJs", "--moduleResolution node"))</TypeScriptBuildConfigurations>
   </PropertyGroup>
  </Target>
  <ItemGroup>
    <DnxInvisibleContent Include="bower.json" />
    <DnxInvisibleContent Include=".bowerrc" />
    <DnxInvisibleContent Include="package.json" />
    <DnxInvisibleFolder Include="wwwroot\bower_components\" />
    <DnxInvisibleFolder Include="wwwroot\node_modules\" />
  </ItemGroup>
  <Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

【问题讨论】:

    标签: typescript angular


    【解决方案1】:

    在 boot.ts 顶部添加这个将有助于解决一些错误:

    /// <reference path="../node_modules/angular2/typings/browser.d.ts"/> 
    

    【讨论】:

    • 谢谢。你是对的,它解决了大部分错误。现在我在几个位置留下了重复的标识符错误:node_modules\angular2\typings、node_modules\angular2\typings\es6-collections 和 typings\browser\ambient\es6-shim。我应该为每一个添加排除条目吗?
    • 你可以分享错误的屏幕截图,以便更详细地了解确切的错误是什么,并且在 package.json 请检查角度版本是否已更新“angular2”:“2.0.0-beta. 14",
    • 我想重新审视这个建议。为什么有必要?它尚未包含在 Angular2 快速入门中。对于许多人来说,它似乎无需添加引用标签就可以工作。
    • 我认为这提供了有关 Visual Studio 2015 中引用标记的解释。blog.johnnyreilly.com/2015/02/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-01-28
    • 2018-04-20
    • 2022-01-14
    • 1970-01-01
    • 2018-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多