stevermeister / ngx-cookie-service

Angular (4.2+ ...12) service for cookies. Originally based on the `ng2-cookies` library.
https://www.npmjs.com/package/ngx-cookie-service
MIT License
547 stars 90 forks source link

Auto cast integer to string #277

Closed AbdrrahimDahmani closed 1 year ago

AbdrrahimDahmani commented 1 year ago

Is your feature request related to a problem? Please describe

When I try to store the quantity value (which is an integer) as a cookie in my angular app, I get an error that says :

Error: src/app/product/product.component.ts:65:33 - error TS2769: No overload matches this call.
  Overload 1 of 2, '(name: string, value: string, expires?: number | Date, path?: string, domain?: string, secure?: boolean, sameSite?: SameSite): void', gave the following error.
    Argument of type 'number' is not assignable to parameter of type 'string'.
  Overload 2 of 2, '(name: string, value: string, options?: CookieOptions): void', gave the following error.
    Argument of type 'number' is not assignable to parameter of type 'string'.

65     this.cookie.set('quantite', this.inputForm.value.quantity);
                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Describe the solution you'd like

It would be perfect if you add an implicit conversion of type integer into string

Describe alternatives you've considered

Instead of automatically converting integers to strings, you can require developers to explicitly cast integers to strings when needed. This makes the code more explicit and can help avoid unexpected type conversions.

Additional context

No response

github-actions[bot] commented 1 year ago

Hello 👋 @AbdrrahimDahmani
Thank you for raising an issue. We will investigate into the issue and get back to you as soon as possible. Please make sure you have given us as much context as possible.
Feel free to raise a PR if you can fix the issue

pavankjadda commented 1 year ago

We can add more types here like

But at the end, when you fetch cookie, it's always going to be string. Hence we recommend using string while storing as well