From 192a1b5b5bc943e19c770f2028cdd59d5246381f Mon Sep 17 00:00:00 2001 From: ExE Boss <3889017+ExE-Boss@users.noreply.github.com> Date: Wed, 16 Oct 2019 23:06:06 +0200 Subject: [PATCH] =?UTF-8?q?feat:=20Add=C2=A0`array.from`=20(#39055)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Add `array.from` * docs(array.from): Add TSDoc comments * docs(array.from): Improve TSDoc --- types/array.from/.editorconfig | 3 +++ types/array.from/array.from-tests.ts | 12 +++++++++++ types/array.from/implementation.d.ts | 8 +++++++ types/array.from/index.d.ts | 31 ++++++++++++++++++++++++++++ types/array.from/polyfill.d.ts | 7 +++++++ types/array.from/shim.d.ts | 4 ++++ types/array.from/tsconfig.json | 22 ++++++++++++++++++++ types/array.from/tslint.json | 1 + 8 files changed, 88 insertions(+) create mode 100644 types/array.from/.editorconfig create mode 100644 types/array.from/array.from-tests.ts create mode 100644 types/array.from/implementation.d.ts create mode 100644 types/array.from/index.d.ts create mode 100644 types/array.from/polyfill.d.ts create mode 100644 types/array.from/shim.d.ts create mode 100644 types/array.from/tsconfig.json create mode 100644 types/array.from/tslint.json diff --git a/types/array.from/.editorconfig b/types/array.from/.editorconfig new file mode 100644 index 0000000000..a0207fa43b --- /dev/null +++ b/types/array.from/.editorconfig @@ -0,0 +1,3 @@ +# This package uses tabs +[*] +indent_style = tab diff --git a/types/array.from/array.from-tests.ts b/types/array.from/array.from-tests.ts new file mode 100644 index 0000000000..8747dfd8fd --- /dev/null +++ b/types/array.from/array.from-tests.ts @@ -0,0 +1,12 @@ +import ArrayFrom = require('array.from'); + +/** + * The `expectType` function from https://www.npmjs.com/package/tsd, + * except instead of returning `void`, it returns `T`. + */ +declare function expectType(t: T): T; + +expectType(ArrayFrom); +expectType(ArrayFrom.implementation); +expectType<() => typeof Array.from>(ArrayFrom.getPolyfill); +expectType<() => typeof Array.from>(ArrayFrom.shim); diff --git a/types/array.from/implementation.d.ts b/types/array.from/implementation.d.ts new file mode 100644 index 0000000000..05ffe88288 --- /dev/null +++ b/types/array.from/implementation.d.ts @@ -0,0 +1,8 @@ +/** + * Creates an array from an array-like or iterable object. + * @param iterable An array-like or iterable object to convert to an array. + * @param mapfn A mapping function to call on every element of the array. + * @param thisArg Value of `this` used to invoke the mapfn. + */ +declare const ArrayFrom: typeof Array.from; +export = ArrayFrom; diff --git a/types/array.from/index.d.ts b/types/array.from/index.d.ts new file mode 100644 index 0000000000..59ac8993ec --- /dev/null +++ b/types/array.from/index.d.ts @@ -0,0 +1,31 @@ +// Type definitions for array.from 1.0 +// Project: https://mths.be/array-from +// Definitions by: ExE Boss +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import implementation = require('./implementation'); +import getPolyfill = require('./polyfill'); +import shim = require('./shim'); + +/** + * Creates an array from an array-like or iterable object. + * @param iterable An iterable object to convert to an array. + * @param mapfn A mapping function to call on every element of the array. + * @param thisArg Value of `this` used to invoke the mapfn. + */ +declare const ArrayFrom: typeof implementation & { + /** + * Gets the optimal `Array.from` implementation to use. + */ + readonly getPolyfill: typeof getPolyfill; + + /** + * Creates an array from an array-like or iterable object. + * @param iterable An iterable object to convert to an array. + * @param mapfn A mapping function to call on every element of the array. + * @param thisArg Value of `this` used to invoke the mapfn. + */ + readonly implementation: typeof implementation; + readonly shim: typeof shim; +}; +export = ArrayFrom; diff --git a/types/array.from/polyfill.d.ts b/types/array.from/polyfill.d.ts new file mode 100644 index 0000000000..75aafbab7d --- /dev/null +++ b/types/array.from/polyfill.d.ts @@ -0,0 +1,7 @@ +import ArrayFrom = require('./implementation'); + +/** + * Gets the optimal `Array.from` implementation to use. + */ +declare function getPolyfill(): typeof ArrayFrom; +export = getPolyfill; diff --git a/types/array.from/shim.d.ts b/types/array.from/shim.d.ts new file mode 100644 index 0000000000..ed158ba747 --- /dev/null +++ b/types/array.from/shim.d.ts @@ -0,0 +1,4 @@ +import ArrayFrom = require('./implementation'); + +declare function shimArrayFrom(): typeof ArrayFrom; +export = shimArrayFrom; diff --git a/types/array.from/tsconfig.json b/types/array.from/tsconfig.json new file mode 100644 index 0000000000..f46eb63a97 --- /dev/null +++ b/types/array.from/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es2015"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictFunctionTypes": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "implementation.d.ts", + "index.d.ts", + "polyfill.d.ts", + "shim.d.ts", + "array.from-tests.ts" + ] +} diff --git a/types/array.from/tslint.json b/types/array.from/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/array.from/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }