[just-clone] Adding new Typings for just-clone module (#39996)

* Typings for just-clone

* Updated tests

* Added more tests

* Moved test
This commit is contained in:
Chris Howard 2019-11-02 07:16:51 +08:00 committed by Jesse Trinity
parent efce94ec94
commit 92a0fe0a28
4 changed files with 58 additions and 0 deletions

9
types/just-clone/index.d.ts vendored Normal file
View File

@ -0,0 +1,9 @@
// Type definitions for just-clone 3.1
// Project: https://github.com/angus-c/just#readme
// Definitions by: Chris Howard <https://github.com/ConnectivityChris>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2
declare function clone<T extends object>(obj: T): T;
export = clone;

View File

@ -0,0 +1,25 @@
import clone = require('just-clone');
const array: string[] = [];
const object: object = {};
const arr = [1, 2, 3];
const subObj = { aa: 1 };
const obj = { a: 3, b: 5, c: arr, d: subObj };
clone(obj); // $ExpectType { a: number; b: number; c: number[]; d: { aa: number; }; }
clone(object); // $ExpectType object
clone(array); // $ExpectType string[]
clone(() => array); // $ExpectType () => string[]
clone(() => {}); // $ExpectType () => void
clone({ a: array }); // $ExpectType { a: string[]; }
clone([{ a: '' }]); // $ExpectType { a: string; }[]
// Incorrect types
clone(); // $ExpectError
clone(1); // $ExpectError
clone(''); // $ExpectError
clone(true); // $ExpectError
clone(false); // $ExpectError
clone(null); // $ExpectError
clone(undefined); // $ExpectError

View File

@ -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",
"just-clone-tests.ts"
]
}

View File

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