Skip to content

Commit

Permalink
Add typings for nookies (DefinitelyTyped#29857)
Browse files Browse the repository at this point in the history
* Add typings for nookies

* Set strictFunctionTypes to true

* Fix get function return type

* Add semicolons
  • Loading branch information
andreasbergqvist authored and sheetalkamat committed Oct 19, 2018
1 parent 5508e44 commit c76ce3b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 0 deletions.
20 changes: 20 additions & 0 deletions types/nookies/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Type definitions for nookies 1.1
// Project: https://github.com/maticzav/nookies#readme
// Definitions by: Andreas Bergqvist <https://github.com/andreasbergqvist>
// 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;
9 changes: 9 additions & 0 deletions types/nookies/nookies-tests.ts
Original file line number Diff line number Diff line change
@@ -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');
24 changes: 24 additions & 0 deletions types/nookies/tsconfig.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
1 change: 1 addition & 0 deletions types/nookies/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

0 comments on commit c76ce3b

Please sign in to comment.