Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from mefechoel/main
Add a Map.has reset with the same semantics as Set.has
- Loading branch information
Showing
5 changed files
with
85 additions
and
0 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
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,9 @@ | ||
/// <reference path="utils.d.ts" /> | ||
|
||
interface Map<K, V> { | ||
has(value: K | (TSReset.WidenLiteral<K> & {})): boolean; | ||
} | ||
|
||
interface ReadonlyMap<K, V> { | ||
has(value: K | (TSReset.WidenLiteral<K> & {})): boolean; | ||
} |
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,41 @@ | ||
import { doNotExecute } from "./utils"; | ||
|
||
doNotExecute(() => { | ||
const map = new Map([ | ||
[1, "1"], | ||
[2, "2"], | ||
[3, "3"], | ||
] as const); | ||
|
||
map.has(4); | ||
|
||
map.has( | ||
// @ts-expect-error | ||
"4", | ||
); | ||
|
||
map.has( | ||
// @ts-expect-error | ||
true, | ||
); | ||
}); | ||
|
||
doNotExecute(() => { | ||
const map = new Map([ | ||
[1, "1"], | ||
[2, "2"], | ||
[3, "3"], | ||
] as const) as ReadonlyMap<1 | 2 | 3, "1" | "2" | "3">; | ||
|
||
map.has(4); | ||
|
||
map.has( | ||
// @ts-expect-error | ||
"4", | ||
); | ||
|
||
map.has( | ||
// @ts-expect-error | ||
true, | ||
); | ||
}); |