google / google/closure-compiler

Improve the type definition of Array.from

Open
#2,966 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
7.7k
Forks
1.2k
Avg merge
2d 12h
Merged PRs (30d)
6

Description

Currently the `arrayLike` param is defined as `string|!IArrayLike|!Iterable` and `opt_mapFn` is defined as `function(this:S, (string|T), number): R=`.

While this is correct it could be more strict and thus easier to use:

If `arrayLike` is a `string`, then `opt_mapFn` is `function(this:S, string, number): R=`. Otherwise it is `function(this:S, T, number): R=`.

```js
/**
* @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from
* @param {string|!IArrayLike|!Iterable} arrayLike
* @param {function(this:S, TT, number): R=} opt_mapFn
* @param {S=} opt_this
* @return {!Array}
* @template T,S,R
* @template TT := cond(eq(typeOfVar('arrayLike'), 'string'), 'string', 'T') =:
*/
Array.from = function(arrayLike, opt_mapFn, opt_this) {};
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.