Skip to content

Commit

Permalink
fix: change Api.AssertUser interface -> type alias (wikimedia-gadgets#46
Browse files Browse the repository at this point in the history
)

The interface causes issues with satisfying the index signature of
`UnknownApiParams` (which is a `Record<string, ...>`). A type alias
instead of an interface allows the index signature to work properly.
See microsoft/TypeScript#15300

Bug: wikimedia-gadgets#45
  • Loading branch information
sportshead authored May 25, 2024
1 parent a5c1bd1 commit 53f80c2
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
5 changes: 3 additions & 2 deletions mw/Api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ interface EditChangedResult extends EditSuccessResult {
newtimestamp: string;
}

interface AssertUser {
// type alias to fix #45
type AssertUser = {
assert: "anon" | "user";
assertUser: string;
}
};

interface WatchStatus {
ns: number;
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "types-mediawiki",
"version": "1.7.0",
"version": "1.7.1",
"description": "TypeScript definitions for MediaWiki JS interface",
"types": "index.d.ts",
"scripts": {
Expand Down
10 changes: 10 additions & 0 deletions test-d/regression/45.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// https://github.com/wikimedia-gadgets/types-mediawiki/issues/45
const api = new mw.Api();
api.postWithEditToken(
api.assertCurrentUser({
formatversion: "2",
action: "edit",
title: "Wikipedia:Sandbox",
appendtext: "Test",
})
);

0 comments on commit 53f80c2

Please sign in to comment.