feat: Add array.from (#39055)

* feat: Add `array.from`

* docs(array.from): Add TSDoc comments

* docs(array.from): Improve TSDoc
This commit is contained in:
ExE Boss 2019-10-16 23:06:06 +02:00 committed by Andrew Branch
parent a66be93748
commit 192a1b5b5b
8 changed files with 88 additions and 0 deletions

View File

@ -0,0 +1,3 @@
# This package uses tabs
[*]
indent_style = tab

View File

@ -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): T;
expectType<typeof Array.from>(ArrayFrom);
expectType<typeof Array.from>(ArrayFrom.implementation);
expectType<() => typeof Array.from>(ArrayFrom.getPolyfill);
expectType<() => typeof Array.from>(ArrayFrom.shim);

8
types/array.from/implementation.d.ts vendored Normal file
View File

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

31
types/array.from/index.d.ts vendored Normal file
View File

@ -0,0 +1,31 @@
// Type definitions for array.from 1.0
// Project: https://mths.be/array-from
// Definitions by: ExE Boss <https://github.com/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;

7
types/array.from/polyfill.d.ts vendored Normal file
View File

@ -0,0 +1,7 @@
import ArrayFrom = require('./implementation');
/**
* Gets the optimal `Array.from` implementation to use.
*/
declare function getPolyfill(): typeof ArrayFrom;
export = getPolyfill;

4
types/array.from/shim.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
import ArrayFrom = require('./implementation');
declare function shimArrayFrom(): typeof ArrayFrom;
export = shimArrayFrom;

View File

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

View File

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