From b7b8a3650b56446d708d28970ecf8df060647c49 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Wed, 16 Aug 2017 19:08:01 +0200 Subject: [PATCH] [json-stringify-safe] add typings (#19026) --- types/json-stringify-safe/index.d.ts | 14 +++++++ .../json-stringify-safe-tests.ts | 39 +++++++++++++++++++ types/json-stringify-safe/tsconfig.json | 22 +++++++++++ types/json-stringify-safe/tslint.json | 1 + 4 files changed, 76 insertions(+) create mode 100644 types/json-stringify-safe/index.d.ts create mode 100644 types/json-stringify-safe/json-stringify-safe-tests.ts create mode 100644 types/json-stringify-safe/tsconfig.json create mode 100644 types/json-stringify-safe/tslint.json diff --git a/types/json-stringify-safe/index.d.ts b/types/json-stringify-safe/index.d.ts new file mode 100644 index 0000000000..f12b3f3660 --- /dev/null +++ b/types/json-stringify-safe/index.d.ts @@ -0,0 +1,14 @@ +// Type definitions for json-stringify-safe 5.0 +// Project: https://github.com/isaacs/json-stringify-safe +// Definitions by: BendingBender +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export = stringify; + +declare function stringify(obj: any, serializer?: stringify.EntryProcessor | null, indent?: string | number | null, decycler?: stringify.EntryProcessor): string; + +declare namespace stringify { + function getSerialize(serializer: EntryProcessor | null, decycler?: EntryProcessor): EntryProcessor; + + type EntryProcessor = (key: string, value: any) => any; +} diff --git a/types/json-stringify-safe/json-stringify-safe-tests.ts b/types/json-stringify-safe/json-stringify-safe-tests.ts new file mode 100644 index 0000000000..08fcae3d65 --- /dev/null +++ b/types/json-stringify-safe/json-stringify-safe-tests.ts @@ -0,0 +1,39 @@ +import stringify = require('json-stringify-safe'); + +interface CircularObj { + circularRef?: CircularObj; + list?: CircularObj[]; +} + +const circularObj: CircularObj = {}; +circularObj.circularRef = circularObj; +circularObj.list = [circularObj, circularObj]; + +stringify(circularObj); +stringify(circularObj, null); +stringify(circularObj, null, 2); +stringify(circularObj, null, null, () => {}); +stringify(circularObj, (key, val) => { + key; // $ExpectType string + val; // $ExpectType any +}, null, (key, val) => { + key; // $ExpectType string + val; // $ExpectType any +}); + +// $ExpectType EntryProcessor +stringify.getSerialize(null, (key, val) => { + key; // $ExpectType string + val; // $ExpectType any +}); +stringify.getSerialize((key, val) => { + key; // $ExpectType string + val; // $ExpectType any +}); +stringify.getSerialize((key, val) => { + key; // $ExpectType string + val; // $ExpectType any +}, (key, val) => { + key; // $ExpectType string + val; // $ExpectType any +}); diff --git a/types/json-stringify-safe/tsconfig.json b/types/json-stringify-safe/tsconfig.json new file mode 100644 index 0000000000..5ba2999d6d --- /dev/null +++ b/types/json-stringify-safe/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "json-stringify-safe-tests.ts" + ] +} diff --git a/types/json-stringify-safe/tslint.json b/types/json-stringify-safe/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/json-stringify-safe/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }