wikimedia-gadgets / types-mediawiki

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

Should `undefined` be allowed in API request parameters? #48

Closed jwbth closed 1 week ago

jwbth commented 2 months ago

While converting https://en.wikipedia.org/wiki/User:BrandonXLF/QuickEdit.js to TypeScript, I came across this:

                    minor: minor.isSelected() ? true : undefined,
                    notminor: minor.isSelected() ? undefined : true,

This is currently disallowed by https://github.com/wikimedia-gadgets/types-mediawiki/blob/37969255e98994a7adc0c7c60ccbbd89dd6dff02/mw/Api.d.ts#L17

image

But mediawiki.api just removes all undefined paramters (just as false ones) in https://github.com/wikimedia/mediawiki/blob/d84806614aed6d99f7e6a64243b8c4f8812a70c8/resources/src/mediawiki.api/index.js#L191.

I have to admit, I use "syntactic sugar" like this in my code as well. Should this be perhaps allowed?

siddharthvp commented 2 months ago

Makes sense to me.

Derugon commented 2 days ago

I've pushed the fix, along with a few JSdoc fixes and annotations. The changes are published in pre-release with tag 1.8.1, as I don't really know how npm publishing works.

siddharthvp commented 2 days ago

The changes are published in pre-release with tag 1.8.1, as I don't really know how npm publishing works.

We have an automated workflow that publishes to npm when a release is created on github. I expect it will also trigger if you edit the pre-release to be a normal release.

Derugon commented 2 days ago

Well, I suppose putting it as pre-release made it not trigger correctly, it worked well after recreating it, thank you!