5

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.

quicky
  • 97
  • 2
  • 14

1 Answers1

5

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.

Update:

The above mentioned pull request was merged so this should no longer be a problem.

Chic
  • 9,836
  • 4
  • 33
  • 62
  • Thanks a lot. I'm new to this TypeScript story. Next time I will already know or even create a definition myself – quicky Apr 28 '15 at 07:53
  • @quicky I'm new to it too but I'm liking it and the community. The [pull request](https://github.com/borisyankov/DefinitelyTyped/pull/4209) has been merged so it should be available. – Chic Apr 28 '15 at 16:58
  • yes you're right, it's pretty nice. Like two weeks ago I didn't even know about TypeScript but it's goin quite fast :) – quicky Apr 29 '15 at 06:40