-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update to 1.41, fix types & cleanup docs #36
Conversation
- add missing comments and update some comments to 1.41. - use code blocks and specify language when possible. - use @link when referencing other members - fix use of null (`{T?} x`) instead of optional (`{T} [x]`) parameters in some cases - remove redundant namespace prefixes - remove redundant @class/@constructor/@extends/@property/@singleton/@static annotations
and update some types
- use shared interfaces for similar types (i.e. ClientNavigator, UserInfo) - add types to some "any" values (i.e. JQuery.client.test) - fix various type issues
If you're willing, you can add the definition mentioned here. #32 |
this is a breaking change check other authors/commits at wikimedia-gadgets#36
- add missing annotations as suggested by @AnYiEE - add missing `@see` annotations - synchronize JSdoc types with TS types - unify `@return`/`@returns` annotations - unify `*`/`any`/`Mixed` types - remove redundant `@chainable`/`@member`/`@method`/`@private`/`@property`/`@returns {void}` annotations
by using a `Color` type to ensure RGB/HSV arrays have at least 3 values
from oversights or revisions by @AnYiEE
to avoid duplicates (and for clarity), by using additional types and interfaces
- add missing `mw.config` properties & fix types of some properties, as suggested by @AnYiEE - fix optional keys being registered either as `null` or `undefined` - infer `mw.Map.get` return type from both selection type and fallback type - update scraper to infer whether a key is optional
|
Yes, it usually always loads after opening VisualEditor. |
From reviews & comments by @AnYiEE - add missing `@see`/`@since` annotations - fix `mw.Api.getMessages`/`loadMessages` not allowing `string` as parameter - fix `mw.format` to only accept string parameters - add missing `options` argument to `mw.requestIdleCallback` - remove redundant `@property`/`@protected` annotations
Avoid passing types when using `mw.messages.exists<types>()` and `mw.messages.set<types>()` to prevent the error "An_instantiation_expression_cannot_be_followed_by_a_property_access" Copied from AnYiEE@6df693a by @AnYiEE
Done, thank you. |
These function are included in the JSdoc and marked as `@private`, but actually they are just in the scope of the module and not even properties of the `mw.language` object.
check other authors/commits at wikimedia-gadgets#36
these function are included in the JSDoc and marked as `@private`, but actually they are just in the scope of the module and not even properties of the `mw.language` object. check other authors/commits at wikimedia-gadgets#36
I changed it in a previous commit to include the `mw.log()` function, but this implementation prevents the `mw.log` object from being extended with additional properties
when `V` may include unknown additional keys We may want to use `Map<V> & Map<Record<string, unknown>>`, but this alternative does not allow mixed autocompletion & typeckecking when passing a key array to `get` or an object to `set`.
- update API param list from Wikipedia API (1.42.0-wmf.18) - fix missing prefix in some interfaces - replace linter exception with a specific rule list, so other issues than intentional ones can still be found
- add autocompletion for token types (and legacy ones) with `postWithToken`/`getToken`/`badToken` - add autocompletion for `getToken` API arguments - fix return type of multiple methods
- add OOJS static properties to `mw.ForeignApi`/`mw.ForeignRest` - replace `Mixed` with `any` in JSdoc for consistency, as it can't be used in some places, so currently both `any` & `Mixed` are used - be more specific with `mw.ForeignApi.getOrigin`/`mw.language.preConvertPlural` return types for autocompletion - add additional signatures to `mw.language.convertNumber` to better infer return type - remove `mw.Map.get()` type parameter, as it allowed to completely bypass type checking - fix `mw.cookie.get`/`mw.cookie.getCrossSite`/`mw.language.gender` not specifying that `null`/`undefined` may be returned - fix `$.textSelection` not allowing `boolean` as argument - fix `ExtensibleMap.values` not allowing unknown properties
check other authors/commits at wikimedia-gadgets#36
check other authors/commits at wikimedia-gadgets#36
check other authors/commits at wikimedia-gadgets#36
refactor(mw.Api): add autocompletion for token types (and legacy ones) with `postWithToken`/`getToken`/`badToken` refactor(mw.Api): add autocompletion for `getToken` API arguments check other authors/commits at wikimedia-gadgets#36
- add OOJS static properties to `mw.ForeignApi`/`mw.ForeignRest` - replace `Mixed` with `any` in JSdoc for consistency, as it can't be used in some places, so currently both `any` & `Mixed` are used - be more specific with `mw.ForeignApi.getOrigin`/`mw.language.preConvertPlural` return types for autocompletion - add additional signatures to `mw.language.convertNumber` to better infer return type - remove `mw.Map.get()` type parameter, as it allowed to completely bypass type checking - fix `mw.cookie.get`/`mw.cookie.getCrossSite`/`mw.language.gender` not specifying that `null`/`undefined` may be returned - fix `$.textSelection` not allowing `boolean` as argument - fix `ExtensibleMap.values` not allowing unknown properties check other authors/commits at wikimedia-gadgets#36
- add missing `@example` annotations - update `mw.Api` comments - make `mw.language.months` a namespace, for the same extensibility reason as with `mw.log` - remove remaining @fires annotations
check other authors/commits at wikimedia-gadgets#36
check other authors/commits at wikimedia-gadgets#36
I've more or less finished re-reading all source code files, so I'm done with the changes of this PR. |
Thanks a lot for the stellar work here. This looks thorough and meticulous. Thanks to @AnYiEE for reviewing it as well. Due to the size of the PR and time constraints, I am unable to go through it all so I'm just merging it as is. We can iterate over any improvements. |
This merge request contains various type and documentation changes, mostly to add MediaWiki 1.41 declarations and to fix various JSdoc inconsistencies and type issues.
Below is a (non exhaustive) list of proposed changes:
JSDoc changes
$.client
,$.textSelection
,mw.html
,mw.loader.store.stats
,mw.message
,mw.notification
,mw.storage.session
,mw.Uri
, andmw.widgets
.mw.Api
andmw.util.isTemporaryUser
.mw.config
comments, along with property types.@link
(instead of@see
, for referencing other members),@see
, and@since
annotations.```
code blocks, and specify language name as much as possible.@return
with@returns
.*
,Mixed
withany
.{T?} x
with{T} [x]
to match expected behavior.@property
and@param
annotations to inner objects when sub-property referencing is used.@class
,@constructor
,@extends
,@fires
,@member
,@method
,@property
,@returns {void}
,@singleton
, and@static
.@private
and@protected
where corresponding TS keywords can be used.@chainable
wherethis
can be used.Type changes
api_params.d.ts
generated list from Wikipedia API (1.42.0-wmf.18).mediaWiki
.libs
,log
, andtrackQueue
tomw
.mw.config
properties.mw.errorLogger
.mw.ForeignApi
andmw.ForeignRest
.mw.language.months
a namespace and specify properties.impl
tomw.loader
and missingmw.loader.moduleRegistry
properties.makeDeprecated
tomw.log
.isParseable
tomw.Message
.acquireTempUserName
andclientPrefs
tomw.user
.addPortlet
andgetArrayParam
tomw.util
.any
values of$.client.test
,$.colorUtil.getColorBrightness
,mw.cookie.set
,mw.language.data
,mw.language.getDigitTransformTable
,mw.language.getSeparatorTransformTable
,mw.language.setData
,mw.loader.implement
,mw.loader.require
,mw.loader.store.items
,mw.storage.clearExpired
,mw.storage.getExpiryKeys
,mw.Title.getUrl
,mw.track
,mw.trackError
,mw.Uri.query
, andmw.Uri.extend
.addOnloadHook
,mw.loader.addScriptTag
,mw.loader.enqueue
,mw.loader.using
,mw.trackSubscribe
,mw.trackUnsubscribe
, andmw.UriRelative
.mw.Api
methods.$.colorUtil
color arrays.mw.util.isIPv4Address
andmw.util.isIPv4Address
.false
literal instead ofboolean
with return type ofmw.loader.store.get
,mw.storage.get
, andmw.user.getRegistration
.mw.loader.load
and module state argument ofmw.loader.state
.mw.ForeignApi.getOrigin
andmw.Uri.toString
.$.colorUtil.getRGB
,mw.language.gender
,mw.language.preConvertPlural
, andmw.log.deprecate
.mw.language.convertNumber
andmw.language.gender
.mw.loader.resolve
.mw.Map.exists
andmw.Map.set
.mw.Api.badToken
,mw.Api.getToken
, andmw.Api.postWithToken
methods.mw.Map
methods, by using anotherExtensibleMap
interface (seewg
variables are not autocompleted #37).Specific type fixes
null
formw.cookie.get
,mw.language.gender
,mw.notification.defaults.type
,mw.Title.newFromFileName
,mw.Title.newFromImg
, andmw.Title.newFromUserInput
.false
formw.cookie.getCrossSite
,mw.notification.defaults.classes
andmw.notification.defaults.id
.$.textSelection()
when called withsetContents
andreplaceSelection
.$.textSelection("getCaretPosition", { startAndEnd: x })
not allowingx: boolean
.$.textSelection("setSelection")
without any options, asstart
is required.$.textSelection
for custom commands, registered via$.textSelection("register")
.api_params.d.ts
interfaces.importStylesheet
andimportStylesheetURI
eventually returningnull
, which actually never appens.defaults
ofmw.Api
,mw.ForeignApi
,mw.ForeignRest
, andmw.Rest
having all properties optional. Some are optional, but some are always defined.mw.Api.assertCurrentUser
return type, this function extends the given query parameters, but does not do any actual API request.mw.Api.chunkedUploadToStash
not allowing an input HTML element as argument.mw.Api.getMessages
andmw.Api.loadMessages
not allowing to query a single string message.mw.Api.loadMessagesIfMissing
returning an API result: the actual query result is consumed by the function, only the booleanmw.Map.set
result is returned.wgCaseSensitiveNamespaces
property ofmw.config
being a list of strings instead of integers.sameSiteLegacy
property to options ofmw.cookie.set
.mw.experiment
tomw.experiments
.mw.ForeignRest
allowing a URI object as argument. However,mw.ForeignRest
does not check for URI objects, whilemw.ForeignApi
does.mw.format
mistakenly allowing anything as parameter replacement.mw.html.element
not allowing attributes to have boolean or number values.mw.language.convertPlural
asking for string instead of integers, when specifying plural forms.commafyNumber
,flipTransform
, andpad
frommw.language
. These declarations are mistakenly included in the API documentation (supposedly missing an@ignore
annotation).mw.loader.register
signature when given multiple modules: all properties should be given multiple times, not only the module name.mw.Map.values
optional keys being required withnull
instead of being optional (and update html scrapper accordingly).mw.Map.get
return type from both selection type and fallback type.mw.Message.parser
andmw.Message.toString
.mw.notify
andmw.notification.notify
not allowingmw.Message
objects as argument.mw.requestIdleCallback
.mw.storage.setExpires
.mw.Title.exists
not allowing a title string as argument.mw.Title.newFromUserInput
not allowing an empty object as options.mw.UriRelative
returning amw.Uri
instance instead of a new constructor. This is also wrongly typed in the MediaWiki source code.mw.Uri
constructor not allowing a boolean as options. This is marked as backward-compatibility in JSDoc, and is still handled in the source code.mw.user.getGroups
andmw.user.getRights
not chaining the promise result correctly when given a callback argument.mw.util.debounce
andmw.util.throttle
not indicating that the function's return type will be discarded.mw.util.getUrl
not allowing parameters to have boolean or number values, while these are explicitely stringified in the function.Other changes
api_params.d.ts
linter exception, so issues (other thanno-empty-interface
) can still be detected.