types-mediawiki icon indicating copy to clipboard operation
types-mediawiki copied to clipboard

Should `undefined` be allowed in API request parameters?

Open jwbth opened this issue 1 year ago • 1 comments
trafficstars

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?

jwbth avatar Jul 21 '24 16:07 jwbth

Makes sense to me.

siddharthvp avatar Jul 22 '24 18:07 siddharthvp

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.

Derugon avatar Oct 11 '24 09:10 Derugon

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.

siddharthvp avatar Oct 11 '24 15:10 siddharthvp

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

Derugon avatar Oct 11 '24 16:10 Derugon