Skip to content

Commit

Permalink
Fix #52: Remove incorrect type guard of exists() from mw.Map
Browse files Browse the repository at this point in the history
  • Loading branch information
Derugon committed Dec 19, 2024
1 parent 4b5e56c commit b2cc064
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions mw/Map.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ export interface ExtensibleMap<V extends Record<string, any>, TX = unknown>
* @returns True if the key exists
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Map.html#.exists
*/
exists<S extends keyof V>(selection: S): selection is S;
exists<S extends string>(selection: S): selection is S;
exists(selection: keyof V): boolean;
exists(selection: string): boolean;

/**
* Get the value of one or more keys.
Expand Down Expand Up @@ -95,7 +95,7 @@ declare global {
* @returns True if the key exists
* @see https://doc.wikimedia.org/mediawiki-core/master/js/mw.Map.html#.exists
*/
exists<S extends keyof V>(selection: S): selection is S;
exists(selection: keyof V): boolean;

/**
* Get the value of one or more keys.
Expand Down
11 changes: 11 additions & 0 deletions test-d/regression/52.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// https://github.com/wikimedia-gadgets/types-mediawiki/issues/52
import { expectType } from "tsd";

declare const map: mw.Map;
declare const k: string;

if (map.exists(k)) {
expectType<string>(k);
} else {
expectType<string>(k);
}

0 comments on commit b2cc064

Please sign in to comment.