From 2093b5c036e41c8ca144fdd6ec2db2b05bdd90b1 Mon Sep 17 00:00:00 2001 From: Duong Tran Date: Sat, 20 Oct 2018 02:57:42 +1100 Subject: [PATCH] [Mobx-cookie] add a new type definition (#29868) * feat: add type definition for mobx-cookie * fix: update version and add strictFunctionTypes to satisfy the test --- types/mobx-cookie/index.d.ts | 17 +++++++++++++++++ types/mobx-cookie/mobx-cookie-tests.ts | 11 +++++++++++ types/mobx-cookie/tsconfig.json | 23 +++++++++++++++++++++++ types/mobx-cookie/tslint.json | 1 + 4 files changed, 52 insertions(+) create mode 100644 types/mobx-cookie/index.d.ts create mode 100644 types/mobx-cookie/mobx-cookie-tests.ts create mode 100644 types/mobx-cookie/tsconfig.json create mode 100644 types/mobx-cookie/tslint.json diff --git a/types/mobx-cookie/index.d.ts b/types/mobx-cookie/index.d.ts new file mode 100644 index 00000000000000..fbf3cc58fdb7c5 --- /dev/null +++ b/types/mobx-cookie/index.d.ts @@ -0,0 +1,17 @@ +// Type definitions for mobx-cookie 1.1 +// Project: https://github.com/will-stone/mobx-cookie#readme +// Definitions by: Duong Tran +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import { CookieAttributes } from 'js-cookie'; + +declare class MobxCookie { + constructor(name: string, options?: CookieAttributes); + + get(): any; + set(value: any, options?: CookieAttributes): void; + remove(): void; +} + +export default MobxCookie; diff --git a/types/mobx-cookie/mobx-cookie-tests.ts b/types/mobx-cookie/mobx-cookie-tests.ts new file mode 100644 index 00000000000000..66965a9f315966 --- /dev/null +++ b/types/mobx-cookie/mobx-cookie-tests.ts @@ -0,0 +1,11 @@ +import MobxCookie from 'mobx-cookie'; + +// Declare a reactive mobx cookie that last for 20 days +const mobxCookie = new MobxCookie('TEST_MOBX_COOKIE', {expires: 20}); + +// Set a new value for the cookie that last for 10 days +mobxCookie.set('MY_VALUE', {expires: 10}); + +const cookieValue = mobxCookie.get(); + +mobxCookie.remove(); diff --git a/types/mobx-cookie/tsconfig.json b/types/mobx-cookie/tsconfig.json new file mode 100644 index 00000000000000..4222165feb43f1 --- /dev/null +++ b/types/mobx-cookie/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "mobx-cookie-tests.ts" + ] +} diff --git a/types/mobx-cookie/tslint.json b/types/mobx-cookie/tslint.json new file mode 100644 index 00000000000000..3db14f85eaf7b9 --- /dev/null +++ b/types/mobx-cookie/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }