js-cookie: parameterized set value

This commit is contained in:
Erik Krogh Kristensen
2019-02-06 18:35:40 +01:00
parent a6e6a509f9
commit 08a32bb403
2 changed files with 5 additions and 5 deletions
+4 -4
View File
@@ -33,7 +33,7 @@ declare namespace Cookies {
secure?: boolean;
}
interface CookiesStatic {
interface CookiesStatic<T extends object = object> {
/**
* Allows default cookie attributes to be accessed, changed, or reset
*/
@@ -42,7 +42,7 @@ declare namespace Cookies {
/**
* Create a cookie
*/
set(name: string, value: string | object, options?: CookieAttributes): void;
set(name: string, value: string | T, options?: CookieAttributes): void;
/**
* Read cookie
@@ -88,10 +88,10 @@ declare namespace Cookies {
* will run the converter first for each cookie. The returned
* string will be used as the cookie value.
*/
withConverter(converter: CookieReadConverter | { write: CookieWriteConverter; read: CookieReadConverter; }): CookiesStatic;
withConverter(converter: CookieReadConverter | { write: CookieWriteConverter<T>; read: CookieReadConverter; }): CookiesStatic;
}
type CookieWriteConverter = (value: string | object, name: string) => string;
type CookieWriteConverter<T extends object> = (value: string | T, name: string) => string;
type CookieReadConverter = (value: string, name: string) => string;
}
+1 -1
View File
@@ -20,7 +20,7 @@ Cookies.remove('name');
Cookies.remove('name', { path: '' });
const Cookies2 = Cookies.noConflict!();
Cookies2; // $ExpectType CookiesStatic
Cookies2; // $ExpectType CookiesStatic<object>
Cookies.set('name', { foo: 'bar' });