I'm creating an app using angularjs
and typescript
. I am using cookies to store same data about user's login and rights etc. I ran into a problem with angular-cookies.d.ts file.
$cookieStore work just fine but according to AngularJS docs this service has been deprecated, so I tried using $cookies instead.
Using $cookies caused an error while compiling Property 'put' does not exist
so I checked the definition and there is really no property with such name in ICookiesService interface.
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;
}
}
Is there actually an error in this type definition or am I doing something wrong? Thanks for your responses.
It appears that the DefinitelyTyped definition has not been updated for Angular 1.4 yet. the ICookiesService interface should be something like:
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;
}
In the future, you can feel free to submit a pull request on GitHub to update the definition. I've created one for this now.
The above mentioned pull request was merged so this should no longer be a problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With