Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve type infererence for fromJS (#1927)
Co-authored-by: khai96_ <hvksmr1996@gmail.com>
- Loading branch information
Showing
2 changed files
with
63 additions
and
1 deletion.
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
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,35 @@ | ||
import { fromJS, List, Map } from 'immutable'; | ||
|
||
{ | ||
// fromJS | ||
|
||
// $ExpectType Collection<unknown, unknown> | ||
fromJS({}, (a: any, b: any) => b); | ||
|
||
// $ExpectType string | ||
fromJS('abc'); | ||
|
||
// $ExpectType List<number> | ||
fromJS([0, 1, 2]); | ||
|
||
// $ExpectType List<number> | ||
fromJS(List([0, 1, 2])); | ||
|
||
// $ExpectType Map<"b" | "a" | "c", number> | ||
fromJS({a: 0, b: 1, c: 2}); | ||
|
||
// $ExpectType Map<string, number> | ||
fromJS(Map({a: 0, b: 1, c: 2})); | ||
|
||
// $ExpectType List<Map<"a", number>> | ||
fromJS([{a: 0}]); | ||
|
||
// $ExpectType Map<"a", List<number>> | ||
fromJS({a: [0]}); | ||
|
||
// $ExpectType List<List<List<number>>> | ||
fromJS([[[0]]]); | ||
|
||
// $ExpectType Map<"a", Map<"b", Map<"c", number>>> | ||
fromJS({a: {b: {c: 0}}}); | ||
} |