[英]How to handle TSLint Errors in my typescript example
I have the following angularjs factory examples written in Typescript but am receiving three TSLint errors: 我有以下用Typescript编写的angularjs工厂示例,但收到三个TSLint错误:
Line 3: expected call-signature: 'FirebaseFactory' to have a typedef 第3行:预期的呼叫签名:“ FirebaseFactory”具有typedef
Line 8: expected call-signature: 'AuthFactory' to have a typedef 第8行:预期的呼叫签名:'AuthFactory'具有typedef
Line 9: expected call-signature to have a typedef 第9行:预期的呼叫签名具有typedef
While I know it is still valid Typescript, I would prefer to ensure that all type checking advantages that TS includes are maintained. 虽然我知道它仍然是有效的Typescript,但我还是希望确保保留TS包括的所有类型检查优点。
module app.services {
export function FirebaseFactory () {
return new Firebase('https://sample.firebaseio.com');
}
angular.module('app.services').factory('firebaseFactory', FirebaseFactory);
export function AuthFactory (DB: Firebase, $firebaseAuth: AngularFireAuthService) {
return function () {
return $firebaseAuth(DB);
};
}
AuthFactory.$inject = ['firebaseFactory', '$firebaseAuth'];
angular.module('app.services').factory('authFactory', AuthFactory);
}
Is there a way to create interfaces so that I only export the interfaces instead of the functions? 有没有一种创建接口的方法,以便我仅导出接口而不是函数? I have done this before with other services that are implemented as classes.
之前,我已经通过实现为类的其他服务来做到这一点。
https://github.com/palantir/tslint#supported-rules says: https://github.com/palantir/tslint#supported-rules说:
"call-signature" checks return type of functions
“呼叫签名”检查函数的返回类型
With this rule (I personally prefer to disable it) you should declare types: 使用此规则(我个人更喜欢禁用它),您应该声明类型:
export function AuthFactory (...): () => AngularFireAuth
Regardless of whether you declare type explicetly or not, or even declare interface: 无论您是否明确声明类型,甚至声明接口:
export var AuthFactory: { (): AngularFireAuth; } = function (...)
outwardly your module looks the same. 从外观上看,您的模块看起来相同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.