我使用的是与语言设置为吞掉角约曼发生器产生一个新项目打字稿。然后运行咕嘟咕嘟建设过程,也是在Web浏览器,所有的工作没有任何更大的问题打开的页面。我只需要替换 REF:主
在 tsd.json
与 REF: 1.4.1
使构建工作。基本上我执行下面的命令:
哟一饮而尽角VIM tsd.json咽一饮而尽服务code。
后来我开了的Visual Studio code 。
现在,Visual Studio的code抱怨,例如,它的无法找到命名空间'NG'。的每次出现,其中的 AngularJS 数据类型使用。它还抱怨 MomentJS 和定义的其他分型*。d.ts
文件。
项目的 tsd.json
是这样的:
{ 版本:V4 回购:borisyankov / DefinitelyTyped 参考:1.4.1 路径:.TMP /分型, 捆绑:.TMP /分型/ tsd.d.ts}
的的.tmp /分型
文件夹包含以下文件:
角UI路由器/角-UI-router.d.tsangularjs /角animate.d.tsangularjs /角cookies.d.tsangularjs /角mocks.d.tsangularjs /角resource.d.tsangularjs /角sanitize.d.tsangularjs / angular.d.tsjQuery的/ jquery.d.ts瞬间/瞬间,node.d.ts瞬间/ moment.d.tstoastr / toastr.d.tstsd.d.ts
要获得原先的Visual Studio code是抱怨的源文件中的一个例子,这里是 navbar.directive.ts
文件:
模块editorTs { 使用严格的; / ** * @ngInject / 导出功能acmeNavbar(){ng.IDirective 返回{ 限制:'E', 范围: { creationDate:'=' }, templateUrl:应用程序/组件/导航栏/ navbar.html', 控制器:NavbarController, controllerAs:虚拟机, bindToController:真 }; } / ** * @ngInject / 类NavbarController { 公共relativeDate:字符串; 构造函数(时刻:moment.MomentStatic){ this.relativeDate =时刻(1444135396045).fromNow(); } }}
在此文件中的Visual Studio code是抱怨 ng.IDirective
键入它的无法找到命名空间'NG'。的并且它抱怨 moment.MomentStatic
键入它的无法找到命名空间时刻的
编辑:
明确地加入以下到顶部 navbar.directive.ts
引用类型定义文件中删除的问题:
///<参考路径=../../../../ TMP /分型/ angularjs / angular.d.ts。/>///<参考路径=../../../../ TMP /分型/时刻/ moment.d.ts。/>
但这些文件在的.tmp / tsd.d.ts
引用已经,它包含以下内容:
///<参考路径=角UI路由器/角-UI-router.d.ts/>///<参考路径=angularjs /角animate.d.ts/>///<参考路径=angularjs /角cookies.d.ts/>///<参考路径=angularjs /角mocks.d.ts/>///<参考路径=angularjs /角resource.d.ts/>///<参考路径=angularjs /角sanitize.d.ts/>///<参考路径=angularjs / angular.d.ts/>///<参考路径=jQuery的/ jquery.d.ts/>///<参考路径=时刻/力矩node.d.ts/>///<参考路径=时刻/ moment.d.ts/>///<参考路径=toastr / toastr.d.ts/>
所以应该没有必要明确地引用文件?
解决方案找不到命名空间'NG'。
请确保该项目没有提及声明模块纳克
。同样的时刻。
基于在问题编辑
明确地加入以下到navbar.directive.ts顶部引用类型定义文件中删除的问题
请使用 tsconfig.json
:https://basarat.gitbooks.io/typescript/content/docs/project/compilation-context.html
I created a new project using the gulp-angular Yeoman generator with language set to TypeScript. Then ran the Gulp build process and also opened the page in a web browser, which all worked without any bigger problems. I only had to replace ref: "master"
in the tsd.json
with ref: "1.4.1"
to make the build work. Basically I executed following commands:
yo gulp-angular
vim tsd.json
gulp
gulp serve
code .
Afterwards I opened the project in Visual Studio Code.
Now, Visual Studio Code complains for example that it "Cannot find namespace 'ng'" for each occurrence where AngularJS data types are used. It also complains about MomentJS and other typings defined in *.d.ts
files.
The project's tsd.json
looks like this:
{
"version": "v4",
"repo": "borisyankov/DefinitelyTyped",
"ref": "1.4.1",
"path": ".tmp/typings",
"bundle": ".tmp/typings/tsd.d.ts"
}
The .tmp/typings
folder contains following files:
angular-ui-router/angular-ui-router.d.ts
angularjs/angular-animate.d.ts
angularjs/angular-cookies.d.ts
angularjs/angular-mocks.d.ts
angularjs/angular-resource.d.ts
angularjs/angular-sanitize.d.ts
angularjs/angular.d.ts
jquery/jquery.d.ts
moment/moment-node.d.ts
moment/moment.d.ts
toastr/toastr.d.ts
tsd.d.ts
To give an example of one of the source files where Visual Studio Code is complaining, here is the navbar.directive.ts
file:
module editorTs {
'use strict';
/** @ngInject */
export function acmeNavbar(): ng.IDirective {
return {
restrict: 'E',
scope: {
creationDate: '='
},
templateUrl: 'app/components/navbar/navbar.html',
controller: NavbarController,
controllerAs: 'vm',
bindToController: true
};
}
/** @ngInject */
class NavbarController {
public relativeDate: string;
constructor(moment: moment.MomentStatic) {
this.relativeDate = moment(1444135396045).fromNow();
}
}
}
In this file Visual Studio Code is complaining about the ng.IDirective
type that it "Cannot find namespace 'ng'" and it is complaining about the moment.MomentStatic
type that it "Cannot find namespace 'moment'".
edit:
Explicitely referencing the type definition files by adding the following to the top of navbar.directive.ts
removes the problem:
/// <reference path="../../../../.tmp/typings/angularjs/angular.d.ts"/>
/// <reference path="../../../../.tmp/typings/moment/moment.d.ts"/>
But these files are already referenced in .tmp/tsd.d.ts
, which contains the following:
/// <reference path="angular-ui-router/angular-ui-router.d.ts" />
/// <reference path="angularjs/angular-animate.d.ts" />
/// <reference path="angularjs/angular-cookies.d.ts" />
/// <reference path="angularjs/angular-mocks.d.ts" />
/// <reference path="angularjs/angular-resource.d.ts" />
/// <reference path="angularjs/angular-sanitize.d.ts" />
/// <reference path="angularjs/angular.d.ts" />
/// <reference path="jquery/jquery.d.ts" />
/// <reference path="moment/moment-node.d.ts" />
/// <reference path="moment/moment.d.ts" />
/// <reference path="toastr/toastr.d.ts" />
So there should be no need to explicitly reference the files?
解决方案Cannot find namespace 'ng'"
Make sure the project contains no reference to declare module ng
. Same for moment.
based on edit in the question:
Explicitely referencing the type definition files by adding the following to the top of navbar.directive.ts removes the problem
Please use a tsconfig.json
: https://basarat.gitbooks.io/typescript/content/docs/project/compilation-context.html