DefinitelyTyped/types/just-clone/just-clone-tests.ts
Chris Howard 92a0fe0a28 [just-clone] Adding new Typings for just-clone module (#39996)
* Typings for just-clone

* Updated tests

* Added more tests

* Moved test
2019-11-01 16:16:51 -07:00

26 lines
771 B
TypeScript

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