wikimedia-gadgets / types-mediawiki

TypeScript definitions for MediaWiki JS interface
GNU General Public License v3.0
23 stars 8 forks source link

Add type definitions for `mw.storage` #18

Closed AnYiEE closed 1 year ago

AnYiEE commented 1 year ago

https://doc.wikimedia.org/mediawiki-core/master/js/#!/api/mw.storage

AnYiEE commented 1 year ago

Thanks for the PR and apologies for the delayed review.

mw.storage also has a setExpires() method which is missing here. All the 5 methods in mw.storage and mw.storage.session have the same types - is there a way we can avoid duplicating them?

The solution I came up with is not to declare the session namespace, but instead use "const session = typeof mw.storage". However, this would result in a loop of "mw.storage.session.session.session", even though we both know that nobody would use it like that, it's not the expected result. Unfortunately, I have not found a solution to this.

Anyway, I will continue to work on completing the type definitions you mentioned, and I hope you can release a version update as soon as possible after that. A few lines of repetitive statements do not affect usage, the lack of type definitions will definitely impact.

Thanks for your work.

siddharthvp commented 1 year ago

The solution I came up with is not to declare the session namespace, but instead use "const session = typeof mw.storage". However, this would result in a loop of "mw.storage.session.session.session"

Generally, interfaces are used to avoid that kind of problem. Done now in latest commit.

AnYiEE commented 1 year ago

Generally, interfaces are used to avoid that kind of problem. Done now in latest commit.

Your solution is effective. Thank you.