Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed Nov 27, 2019
1 parent e7b2f2b commit 86e275e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/baselines/reference/arrayFlatMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,18 @@ const array: number[] = [];
const readonlyArray: ReadonlyArray<number> = [];
array.flatMap((): ReadonlyArray<number> => []); // ok
readonlyArray.flatMap((): ReadonlyArray<number> => []); // ok

// #19535

const [x] = [1].flatMap(undefined as () => number[] | number[][]);
x == 1;


//// [arrayFlatMap.js]
var array = [];
var readonlyArray = [];
array.flatMap(function () { return []; }); // ok
readonlyArray.flatMap(function () { return []; }); // ok
// #19535
var x = [1].flatMap(undefined)[0];
x == 1;
11 changes: 11 additions & 0 deletions tests/baselines/reference/arrayFlatMap.symbols
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,14 @@ readonlyArray.flatMap((): ReadonlyArray<number> => []); // ok
>flatMap : Symbol(ReadonlyArray.flatMap, Decl(lib.es2019.array.d.ts, --, --))
>ReadonlyArray : Symbol(ReadonlyArray, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.core.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2016.array.include.d.ts, --, --), Decl(lib.es2019.array.d.ts, --, --))

// #19535

const [x] = [1].flatMap(undefined as () => number[] | number[][]);
>x : Symbol(x, Decl(arrayFlatMap.ts, 7, 7))
>[1].flatMap : Symbol(Array.flatMap, Decl(lib.es2019.array.d.ts, --, --))
>flatMap : Symbol(Array.flatMap, Decl(lib.es2019.array.d.ts, --, --))
>undefined : Symbol(undefined)

x == 1;
>x : Symbol(x, Decl(arrayFlatMap.ts, 7, 7))

17 changes: 17 additions & 0 deletions tests/baselines/reference/arrayFlatMap.types
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,20 @@ readonlyArray.flatMap((): ReadonlyArray<number> => []); // ok
>(): ReadonlyArray<number> => [] : () => readonly number[]
>[] : undefined[]

// #19535

const [x] = [1].flatMap(undefined as () => number[] | number[][]);
>x : number | number[]
>[1].flatMap(undefined as () => number[] | number[][]) : (number | number[])[]
>[1].flatMap : <U, This = undefined>(callback: (this: This, value: number, index: number, array: number[]) => U, thisArg?: This) => (U extends readonly (infer V)[] ? V : U)[]
>[1] : number[]
>1 : 1
>flatMap : <U, This = undefined>(callback: (this: This, value: number, index: number, array: number[]) => U, thisArg?: This) => (U extends readonly (infer V)[] ? V : U)[]
>undefined as () => number[] | number[][] : () => number[] | number[][]
>undefined : undefined

x == 1;
>x == 1 : boolean
>x : number | number[]
>1 : 1

5 changes: 5 additions & 0 deletions tests/cases/compiler/arrayFlatMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ const array: number[] = [];
const readonlyArray: ReadonlyArray<number> = [];
array.flatMap((): ReadonlyArray<number> => []); // ok
readonlyArray.flatMap((): ReadonlyArray<number> => []); // ok

// #19535

const [x] = [1].flatMap(undefined as () => number[] | number[][]);
x == 1;

0 comments on commit 86e275e

Please sign in to comment.