我正在使用angularjs和typescript创建一个应用程序。我正在使用cookie存储关于用户登录和权限等的相同数据。
$cookieStore工作得很好,但是根据AngularJS文档的说法,这个服务已经被废弃了,所以我尝试使用$cookies。使用$cookies会导致编译Property 'put' does not exist时出错,所以我检查了定义,在ICookiesService接口中实际上没有这样的属性。
declare module "angular-cookies" {
var _: string;
export = _;
}
declare module angular.cookies {
interface ICookiesService {
[index: string]: any;
}
interface ICookieStoreService {
get(key: string): any;
put(key: string, value: any): void;
remove(key: string): void;
}
}这个类型的定义实际上是错误的,还是我做错了什么?谢谢你的答复。
发布于 2015-04-27 21:01:48
看来DefinitelyTyped的定义还没有更新到角1.4。ICookiesService接口应该类似于:
interface ICookiesService {
get(key: string): string;
getObject(key: string): any;
getAll(): any;
put(key: string, value: string, options?: any): void;
putObject(key: string, value: any, options?: any): void;
remove(key: string, options?: any): void;
}将来,您可以在GitHub上提交一个拉请求来更新定义。这件事我已经有创造了一个了。
更新:
上面提到的拉请求被合并了,所以这应该不再是一个问题。
https://stackoverflow.com/questions/29897971
复制相似问题