Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular-cookies DefinitelyTyped

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.

like image 266
quicky Avatar asked Apr 27 '15 14:04

quicky


1 Answers

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.

like image 159
Chic Avatar answered Oct 09 '22 13:10

Chic