采用了棱角分明2打字稿和命名空间 [英] Using Angular 2 with TypeScript and Namespaces

查看:133
本文介绍了采用了棱角分明2打字稿和命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在建设一个大规模应用的过程中,我试图评估打字稿及Angular2为基础的技术来使用。

不幸的是,我遇到了命名空间我自己的打字稿的文件,一旦我开始使用Angular2的问题。

服用英雄教程的例子,我试过使之符合我怎么会看到我自己的申请被结构化的。

   - 应用程序
- boot.ts - 英雄
- 组件
--- HeroDetail.ts
--- HeroList.ts - 接口
--- IHero.ts

在这个结构中,然后我试图使用命名空间为每个逻辑区域以分组。这导致IHero看起来像这样(例如):

 命名空间Heroes.Interfaces
{
  导出接口IHero
  {
    身份证号;
    名称:字符串;
  }
}

在此构建筑项目运作良好,直到我尝试的方式添加到角组合:从'angular2 /核心进口{}组件;
当发生这种情况时,文件丢失到其他code所有引用在同一个命名空间,有没有办法让它发现它们。

我见过的<一个href=\"http://stackoverflow.com/questions/32531405/why-does-importing-a-node-module-break-my-internal-typescript-namespaces-in-atom\">this问题问同样的问题。在那里,答案提到了变通。出于这个原因,我想这是可能的,但更重要的是我想知道为什么它在一分钟是不?这是一个错误或设计?
我一直在考虑提高其在TS GitHub上,但我想会好一点知情才去这条路线。

感谢您的任何意见!


解决方案

  

这是一个错误或设计?


这是由设计。如果你正在使用的文件模块不使用命名空间。 每个文件都已经是一个模块。而整个项目需要的模块加载器。

I'm in the process of building a large-scale application and I'm trying to evaluate TypeScript and Angular2 as the base technologies to use.

Unfortunately, I'm having an issue with namespacing my own TypeScript files once I begin using Angular2.

Taking the example of the Heroes tutorial, I tried to make it match how I would see my own application being structured.

- app 
-- boot.ts

- Heroes
-- Components
--- HeroDetail.ts
--- HeroList.ts

-- Interfaces
--- IHero.ts

Within this structure, I then attempted to use namespaces for each logical area in order to group them. This resulted in IHero looking like this (for example):

namespace Heroes.Interfaces
{
  export interface IHero
  {
    Id: number;
    Name: string;
  }
}

Building the project in this structure works well until I attempt to add Angular into the mix by way of: import {Component} from 'angular2/core'; When this happens, the file loses all references to other code in the same namespace and there's no way to make it discover them.

I've seen this question asked about the same issue. There, the answer mentions "work arounds". For this reason I'm thinking it's POSSIBLE, but more than that I'm wondering why it ISN'T at the minute? Is this a bug or by design? I've been considering raising it on the TS GitHub but I would like to be a little better informed before going down that route.

Thanks for any advice!

解决方案

Is this a bug or by design?

This is by design. Don't use namespaces if you are using file modules. Each file is already a module. And your whole project needs a module loader.

这篇关于采用了棱角分明2打字稿和命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆