简体   繁体   English

运行ng serve时未定义命名空间声明,但intellisense确实将其提取

[英]Namespace declaration not defined when running ng serve, but intellisense does pick it up

I am working with the Azure Atlas library and decided to make my own typings for the third party library. 我正在使用Azure Atlas库,并决定为第三方库进行自己的输入。 I have defined a typings file atlas.d.ts in the project structure, which intellisense in VS Code does pick up and allow me to use the typings. 我已经在项目结构中定义了一个atlas.d.ts文件atlas.d.ts ,VS Code中的intellisense确实可以接收并允许我使用打字。 The problem is, upon running ng serve , I get an error: 问题是,在运行ng serve ,出现错误:

ReferenceError: atlas is not defined ReferenceError:未定义图集

In the typings I simply declared a namespace as such: 在类型中,我只是这样声明了一个名称空间:

declare namespace atlas {
    // ... Rest of the the interfaces and classes here
}

The issue is that I have read all the documentation on implementing global namespaces or modules in typescript as well as read through a couple of stack overflow posts, modifying the tsconfig to take into account the atlas.d.ts file, even though the Angular-CLI ts config out of the box will already include all typings files, but no luck. 问题是我已经阅读了有关在tsconfig实现全局名称空间或模块的所有文档,并阅读了几个堆栈溢出帖子,并修改了tsconfig以考虑到atlas.d.ts文件,即使Angular-开箱即用的CLI ts config配置将已经包含所有类型的文件,但是没有运气。

Any idea as to what could be causing ng serve to not take typings into account? 关于可能导致ng serve不输入的任何想法吗? You can find the repo I am working with here 您可以在这里找到我正在使用的仓库

So I solved the issue. 所以我解决了这个问题。 I am not sure why this works but it does. 我不知道为什么这行得通,但确实行得通。 The way I set up the project was, I would lazy load in the dependency resources into the project only when the Atlas Map needed to be rendered. 设置项目的方式是,仅当需要渲染Atlas Map时,我才会将依赖项资源延迟加载到项目中。 As per the Azure Atlas documentation here . 根据此处的Azure Atlas文档。 I need to have the Azure Maps Script and Stylesheet in the Head of the index.html file for the project, which is what I was going to do dynamically when the map was needed. 我需要在该项目的index.html文件的标题中具有Azure Maps脚本和样式表,这是我在需要地图时要动态进行的操作。 But in order to get the namespace to work, I manually added these two lines into the HEAD of my index.html file at the root of the project and now the atlas namespace I defined is recognized. 但是为了使命名空间正常工作,我将这两行手动添加到了项目根目录下的index.html文件的HEAD中,现在可以识别我定义的地图集命名空间。

<link rel="stylesheet" href="https://atlas.microsoft.com/sdk/css/atlas.min.css?api-version=1" type="text/css" />
<script src="https://atlas.microsoft.com/sdk/js/atlas.min.js?api-version=1"></script>

If anyone can give me some insight as to why this is the case? 如果有人可以给我一些见解,为什么会这样呢? I am really interested as to why angular flipped on my own defined namespace and would not recognize it until I added the library that the typings would be registered for, even if they hadn't been needed yet. 我对为什么angular翻转到我自己定义的命名空间上感到非常感兴趣,直到我添加了将要为其输入类型的库(即使现在还不需要它们)之后才意识到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM