mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
🤖 Merge PR #46399 array.prototype.flatmap: support ReadonlyArray by @mpartel
* array.prototype.flatmap: support ReadonlyArray * array.prototype.flatmap: support readonly result from callback
This commit is contained in:
parent
b27845dbea
commit
59020cc50a
@ -45,3 +45,12 @@ getPolyfill()(["foo"], word => word.split("")); // $ExpectType string[]
|
||||
|
||||
// `shim` installs a flatMap implementation in `Array` prototype and returns it
|
||||
shim()(["foo"], word => word.split("")); // $ExpectType string[]
|
||||
|
||||
// `ReadonlyArray` is supported
|
||||
(["foo"] as ReadonlyArray<string>).flatMap(word => word.split("")); // $ExpectType string[]
|
||||
|
||||
// Readonly result from callback is supported
|
||||
flatMap([[1], [2]], a => a as ReadonlyArray<number>); // $ExpectType number[]
|
||||
flatMap([[1], [2]] as ReadonlyArray<ReadonlyArray<number>>, a => a); // $ExpectType number[]
|
||||
([[1], [2]]).flatMap(a => a as ReadonlyArray<number>); // $ExpectType number[]
|
||||
([[1], [2]] as ReadonlyArray<ReadonlyArray<number>>).flatMap(a => a); // $ExpectType number[]
|
||||
|
||||
9
types/array.prototype.flatmap/auto.d.ts
vendored
9
types/array.prototype.flatmap/auto.d.ts
vendored
@ -1,6 +1,13 @@
|
||||
interface Array<T> {
|
||||
flatMap<U, R extends object | undefined = undefined>(
|
||||
fn: (this: R, x: T, index: number, array: this) => U[],
|
||||
fn: (this: R, x: T, index: number, array: this) => ReadonlyArray<U>,
|
||||
thisArg?: R
|
||||
): U[];
|
||||
}
|
||||
|
||||
interface ReadonlyArray<T> {
|
||||
flatMap<U, R extends object | undefined = undefined>(
|
||||
fn: (this: R, x: T, index: number, array: this) => ReadonlyArray<U>,
|
||||
thisArg?: R
|
||||
): U[];
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
// This is the same type as the callable signature in `FlatMap` in `index.d.ts`.
|
||||
declare function flatMap<A, B, T extends object | undefined = undefined>(
|
||||
xs: ReadonlyArray<A>,
|
||||
fn: (this: T, x: A, index: number, array: A[]) => B[],
|
||||
fn: (this: T, x: A, index: number, array: A[]) => ReadonlyArray<B>,
|
||||
thisArg?: T
|
||||
): B[];
|
||||
export = flatMap;
|
||||
|
||||
2
types/array.prototype.flatmap/index.d.ts
vendored
2
types/array.prototype.flatmap/index.d.ts
vendored
@ -10,7 +10,7 @@ import flatMapImpl = require("./implementation");
|
||||
interface FlatMap {
|
||||
<A, B, T extends object | undefined = undefined>(
|
||||
xs: ReadonlyArray<A>,
|
||||
fn: (this: T, x: A, index: number, array: A[]) => B[],
|
||||
fn: (this: T, x: A, index: number, array: A[]) => ReadonlyArray<B>,
|
||||
thisArg?: T
|
||||
): B[];
|
||||
getPolyfill(): typeof flatMapImpl;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user