【发布时间】:2015-11-20 17:59:10
【问题描述】:
我尝试将现有的 Angular 应用迁移到 typescript(1.5.3 版):
代码如下:
'use strict';
angular.module('x')
.directive('tabsPane', TabsPane)
function TabsPane(itemTabs) {
return {
restrict: 'E',
compile: compileTabs
};
function compileTabs(tElement) {
var template = createTabsTemplate(); //function which i don't include here for brevity
tElement.append(template);
}}
当我编译 javascript 我得到:
错误 TS2345: 类型参数 '(itemTabs: any) => { restrict: string;编译: (tElement: any) => void; }' 不能分配给“any[]”类型的参数。 类型 '(itemTabs: any) => { restrict: string; 中缺少属性 'push'编译: (tElement: any) => void; }'。
我试图理解为什么它在这里抱怨我去了 angular 的 typescript 定义:
打字稿不知何故暗示了这个定义
directive(name: string, inlineAnnotatedFunction: any[]): IModule;
以下定义更合适:
directive(名称:字符串,directiveFactory:IDirectiveFactory):IModule;
我对 typescript 完全陌生,所以我认为我做错了什么,但我找不到任何与 google 相关的内容。
【问题讨论】:
-
晚了但是:在我的情况下,需要刷新一些挥之不去的缓存。对我来说解决方案有点老套,但我将返回类型设置为
:void保存了文件,然后删除了返回类型并再次保存。瞧,没有更多错误了。
标签: angularjs typescript typescript1.5