Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(micro-dash): improve typing of
forEach
Closes #22
- Loading branch information
Showing
2 changed files
with
117 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
projects/micro-dash/src/typing-tests/collection/for-each.dts-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { forEach } from '../../lib/collection'; | ||
|
||
interface Obj { | ||
a: 1; | ||
b: string; | ||
} | ||
|
||
declare const array: number[]; | ||
declare const arrayOrN: number[] | null; | ||
declare const arrayOrU: number[] | undefined; | ||
|
||
// $ExpectType number[] | ||
forEach( | ||
array, | ||
( | ||
// $ExpectType number | ||
val, | ||
// $ExpectType number | ||
index, | ||
) => {}, | ||
); | ||
// $ExpectType number[] | null | ||
forEach( | ||
arrayOrN, | ||
( | ||
// $ExpectType number | ||
val, | ||
// $ExpectType number | ||
index, | ||
) => {}, | ||
); | ||
// $ExpectType number[] | undefined | ||
forEach( | ||
arrayOrU, | ||
( | ||
// $ExpectType number | ||
val, | ||
// $ExpectType number | ||
index, | ||
) => {}, | ||
); | ||
|
||
declare const tuple: [string, Date]; | ||
declare const tupleOrN: [string, Date] | null; | ||
declare const tupleOrU: [string, Date] | undefined; | ||
|
||
// $ExpectType [string, Date] | ||
forEach( | ||
tuple, | ||
( | ||
// $ExpectType string | Date | ||
val, | ||
// $ExpectType number | ||
index, | ||
) => {}, | ||
); | ||
// $ExpectType [string, Date] | null | ||
forEach( | ||
tupleOrN, | ||
( | ||
// $ExpectType string | Date | ||
val, | ||
// $ExpectType number | ||
index, | ||
) => {}, | ||
); | ||
// $ExpectType [string, Date] | undefined | ||
forEach( | ||
tupleOrU, | ||
( | ||
// $ExpectType string | Date | ||
val, | ||
// $ExpectType number | ||
index, | ||
) => {}, | ||
); | ||
|
||
declare const obj: Obj; | ||
declare const objOrN: Obj | null; | ||
declare const objOrU: Obj | undefined; | ||
|
||
// $ExpectType Obj | ||
forEach( | ||
obj, | ||
( | ||
// $ExpectType string | 1 | ||
val, | ||
// $ExpectType "a" | "b" | ||
key, | ||
) => {}, | ||
); | ||
// $ExpectType Obj | null | ||
forEach( | ||
objOrN, | ||
( | ||
// $ExpectType string | 1 | ||
val, | ||
// $ExpectType "a" | "b" | ||
key, | ||
) => {}, | ||
); | ||
// $ExpectType Obj | undefined | ||
forEach( | ||
objOrU, | ||
( | ||
// $ExpectType string | 1 | ||
val, | ||
// $ExpectType "a" | "b" | ||
key, | ||
) => {}, | ||
); |