[json-stringify-safe] add typings (#19026)

This commit is contained in:
Dimitri Benin
2017-08-16 19:08:01 +02:00
committed by Mohamed Hegazy
parent e395189807
commit b7b8a3650b
4 changed files with 76 additions and 0 deletions

14
types/json-stringify-safe/index.d.ts vendored Normal file
View File

@@ -0,0 +1,14 @@
// Type definitions for json-stringify-safe 5.0
// Project: https://github.com/isaacs/json-stringify-safe
// Definitions by: BendingBender <https://github.com/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;
}

View File

@@ -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
});

View File

@@ -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"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }