From c76ce3bec09cc34ca9c18fb5b0a118ad04c03232 Mon Sep 17 00:00:00 2001 From: Andreas Bergqvist Date: Fri, 19 Oct 2018 17:54:22 +0200 Subject: [PATCH] Add typings for nookies (#29857) * Add typings for nookies * Set strictFunctionTypes to true * Fix get function return type * Add semicolons --- types/nookies/index.d.ts | 20 ++++++++++++++++++++ types/nookies/nookies-tests.ts | 9 +++++++++ types/nookies/tsconfig.json | 24 ++++++++++++++++++++++++ types/nookies/tslint.json | 1 + 4 files changed, 54 insertions(+) create mode 100644 types/nookies/index.d.ts create mode 100644 types/nookies/nookies-tests.ts create mode 100644 types/nookies/tsconfig.json create mode 100644 types/nookies/tslint.json diff --git a/types/nookies/index.d.ts b/types/nookies/index.d.ts new file mode 100644 index 0000000000..1eaab3ce64 --- /dev/null +++ b/types/nookies/index.d.ts @@ -0,0 +1,20 @@ +// Type definitions for nookies 1.1 +// Project: https://github.com/maticzav/nookies#readme +// Definitions by: Andreas Bergqvist +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.8 + +import { NextContext } from 'next'; +import { CookieParseOptions, CookieSerializeOptions } from 'cookie'; + +export function parseCookies(ctx: NextContext, options?: CookieParseOptions): { [key: string]: string }; +export function setCookie(ctx: NextContext, name: string, value: string, options?: CookieSerializeOptions): void; +export function destroyCookie(ctx: NextContext, name: string): void; + +declare const Nookies: { + set(ctx: NextContext, name: string, value: string, options?: CookieSerializeOptions): void; + get(ctx: NextContext, options?: CookieParseOptions): { [key: string]: string }; + destroy(ctx: NextContext, name: string): void; +}; + +export default Nookies; diff --git a/types/nookies/nookies-tests.ts b/types/nookies/nookies-tests.ts new file mode 100644 index 0000000000..2fe560affc --- /dev/null +++ b/types/nookies/nookies-tests.ts @@ -0,0 +1,9 @@ +import nookies, { parseCookies, setCookie, destroyCookie } from 'nookies'; + +nookies.set({ pathname: '', query: {}, asPath: ''}, 'test-cookie', 'test-value'); +nookies.get({ pathname: '', query: {}, asPath: ''}); +nookies.destroy({ pathname: '', query: {}, asPath: ''}, 'test-cookie'); + +parseCookies({ pathname: '', query: {}, asPath: ''}); +setCookie({ pathname: '', query: {}, asPath: ''}, 'test-cookie', 'test-value'); +destroyCookie({ pathname: '', query: {}, asPath: ''}, 'test-cookie'); diff --git a/types/nookies/tsconfig.json b/types/nookies/tsconfig.json new file mode 100644 index 0000000000..15118a6178 --- /dev/null +++ b/types/nookies/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true, + "strictFunctionTypes": true + }, + "files": [ + "index.d.ts", + "nookies-tests.ts" + ] +} diff --git a/types/nookies/tslint.json b/types/nookies/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/nookies/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }