-
Notifications
You must be signed in to change notification settings - Fork 9
Expose all types #40
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
Open
Derugon
wants to merge
31
commits into
wikimedia-gadgets:main
Choose a base branch
from
Derugon:expose
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Expose all types #40
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Only keep type renaming changes, remove all other type changes. There are more type improvements we can do easily with the API params, so these changes will instead be proposed in another PR.
some interfaces were added to the JSdoc shipped with MW 1.42, so use the "official" names if they differ from the ones used in this PR
moved `mw.Notification` to `mw.notification.Notification` in the previous commit (so all things provided by the `mw.notification` RL module are in the `mw.notification` namespace)
Move some things from the `mw` namespace to sub-namespaces - move `mw.CacheReport/LimitReport/LimitReportValue` to `mw.PageParseReport.Cache/Limit/LimitValue` - move `mw.SearchIndexEntry` to `mw.SearchIndex.Entry` - move `mw.TitleLike` to `mw.Title.Like` - rename `mw.cookie.CookieOptions` to `mw.cookie.Options`
PR wikimedia-gadgets#41 also changes API parameter type names, to fix various name conflicts and parameter prefix issues, so I move it from this PR to PR wikimedia-gadgets#41.
We may add API response types later. In the same way as with `mw.Api.Params` and `mw.Api.UnknownParams`, we may want to use `mw.Api.Response` as an interface with common response parameters (e.g. `warnings`, `continue`).
missed some in previous merges
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Expose all local types used in all declaration files, inside the
mwnamespace or nested namespaces injqueryandmw.To review these changes, I highly suggest to hide whitespace differences, since most of the lines have whitespace differences, and diff editors seem to mostly not align anything with these on.
Context
Custom types and interfaces are used by functions or namespace constants, either to simplify declarations or for extensibility/maintenance reasons. Most of these types are not declared in the JSDoc from the MediaWiki source code, and are specific to this package, so they are implemented as local types within modules. When they need to be accessible to other nested modules of this package or to npm users, types are exported within their module.
Motivations
There are two main motivations for these changes.
1. Remove sub-module dependencies
Remove dependencies to nested modules of
types-mediawiki, so declaration files can be merged, split and moved from one file to another without affecting users.2. Expose to end-users
Allow to use JSDoc or TypeScript types to specify the type of variables, and not only rely on type inference.
For example, the first argument of
mw.experiments.getBucketis an instance of theExperimentinterface. Suppose we want to call this function with a new object that satisfies theExperimentinterface. If we create the object directly when calling the function, the first argument is type-checked properly.But if we want to declare the experiment separately in an
experimentvariable, there is no easy way to specify its type directly.We could use
typeofin some situations to get the type of already existing object properties ormwnamespace constants, but there is not always a constant or property somewhere in themwnamespace with the type we're looking for. This becomes even harder when trying to extend existing interfaces when writing custom ResourceLoader modules, since a lot of interfaces are not accessible at all.With the type changes proposed in this PR, the previous example would be written:
Proposed changes
Move local types (whether exported or not) to
mworjquerynamespaces, by using existing (or creating new) nested namespaces.Remove redundant type name prefixes/suffixes, when the namespace provides the same information.
To simplify the migration process and prevent breaking existing code:
Add type synonyms to keep existing exports from nested modules, and
@deprecatethese exports in favor of global declarations (e.g./** @deprecated */ export type X = mw.X).Set
mwas default export of the root module, so import syntax can still be used if desired, such as to prevent naming conflicts with other JQuery libraries.Alternatives
Below are alternative solutions, that still meet the motivations mentioned above, and may be preferred from the previous implementation.
JQuerynamespace.Proposed type names
Below is an exhaustive list of proposed type changes.
JQuery modules (
jquery)clientClientJQuery.ClientClientNavigatorJQuery.Client.NavigatorClientProfileLayoutJQuery.Client.Profile.LayoutClientProfileNameJQuery.Client.Profile.NameClientProfilePlatformJQuery.Client.Profile.PlatformComparisonOperatorJQuery.Client.ComparisonOperatorClientSupportConditionJQuery.Client.SupportMap.ConditionUndirectedClientSupportMapJQuery.Client.SupportMap.UndirectedClientSupportMapJQuery.Client.SupportMapClientProfileJQuery.Client.ProfilecollapsibleTabsCollapsibleTabsOptionsJQuery.CollapsibleTabs.OptionsCollapsibleTabsStaticJQuery.CollapsibleTabs.StaticCollapsibleTabsJQuery.CollapsibleTabscolorUtilColorJQuery.ColorUtil.ColorColorUtilJQuery.ColorUtilconfirmableRequiredOrUndefinedmw.RequiredOrUndefinedConfirmableJQuery.ConfirmableOptionsJQuery.Confirmable.OptionsRequiredOptionsJQuery.Confirmable.RequiredOptionsI18NJQuery.Confirmable.I18NfootHovzerFootHovzerJQuery.FootHovzerhighlightTextMethodJQuery.HighlightText.MethodHighlightTextJQuery.HighlightTextOptionsJQuery.HighlightText.OptionslengthLimitFilterFunctionJQuery.LengthLimit.FilterFunctionTrimResultJQuery.LengthLimit.TrimResultmakeCollapsibleOptionsJQuery.MakeCollapsible.OptionsspinnerSizeJQuery.Spinner.SizeTypeJQuery.Spinner.TypeOptionsJQuery.Spinner.OptionssuggestionsDeviceJQuery.Suggestions.DeviceDirectionJQuery.Suggestions.DirectionContextJQuery.Suggestions.ContextOptionsJQuery.Suggestions.OptionsResultOptionsJQuery.Suggestions.Options.ResultSpecialOptionsJQuery.Suggestions.Options.SpecialUpdateOptionsJQuery.Suggestions.Options.UpdatetablesorterParserTypeMapJQuery.TableSorter.ParserTypeMapParserMapJQuery.TableSorter.ParserMapMultiSortKeyJQuery.TableSorter.MultiSortKeyParserFromTypeJQuery.TableSorter.ParserFromTypeParserFromKeyJQuery.TableSorter.ParserFromKeyParserJQuery.TableSorter.ParserTableSorterJQuery.TableSorterOptionsJQuery.TableSorter.OptionstextSelectionTextSelectionEncapsulateOptionsJQuery.TextSelection.EncapsulateSelectionOptionsGetCaretPositionOptionsJQuery.TextSelection.GetCaretPositionOptionsSetSelectionOptionsJQuery.TextSelection.SetSelectionOptionsScrollToCaretPositionOptionsJQuery.TextSelection.ScrollToCaretPositionOptionstipsyStringProviderJQuery.Tipsy.StringProviderMethodsOfmw.MethodsOfNSDirectionJQuery.Tipsy.NSDirectionEWDirectionJQuery.Tipsy.EWDirectionDirectionJQuery.Tipsy.DirectionJQueryTipsyJQuery.TipsyOptionsJQuery.Tipsy.OptionsTipsyJQuery.Tipsy.TipsyupdateTooltipAccessKeysKeyModifierJQuery.TooltipAccessKeys.KeyModifierTooltipAccessKeysJQuery.TooltipAccessKeysMediaWiki modules (
mw)ApiTailmw.TailTypeOrArraymw.TypeOrUnionArrayReplaceValuemw.ReplaceValueUnknownApiParamsmw.Api.UnknownParamsApiResponsemw.Api.UnknownResponseRevisionmw.Api.RevisionEditResultmw.Api.Response.EditEditFailureResultmw.Api.Response.Edit.FailureEditSuccessResultmw.Api.Response.Edit.SuccessEditNoChangeResultmw.Api.Response.Edit.NoChangeEditChangedResultmw.Api.Response.Edit.ChangedAssertUsermw.Api.AssertUserRollbackInfomw.Api.Response.RollbackFinishUploadmw.Api.FinishUploadconfigPageParseReportmw.PageParseReportCacheReportmw.PageParseReport.CacheLimitReportmw.PageParseReport.LimitLimitReportValuemw.PageParseReport.LimitValueconfirmCloseWindowOptionsmw.ConfirmCloseWindow.OptionsConfirmCloseWindowmw.ConfirmCloseWindowcookieSameSitemw.cookie.SameSitemw.cookie.CookieOptionsmw.cookie.OptionsdebugLogEntryTypemw.Debug.LogEntryTypeDatamw.Debug.DataFilemw.Debug.FileLogEntrymw.Debug.LogEntryQuerymw.Debug.QueryexperimentsExperimentmw.experiments.ExperimenthookHookmw.HookPostEditDatamw.PostEditDataSearchIndexmw.SearchIndexSearchIndexEntrymw.SearchIndex.EntryEditRecoverymw.EditRecoveryindexIdleCallbackOptionsmw.IdleCallbackOptionsObjectAnalyticEventDatamw.AnalyticEvent.ObjectDataAnalyticEventDatamw.AnalyticEvent.DataErrorAnalyticEventDatamw.AnalyticEvent.ErrorDataAnalyticEventmw.AnalyticEventAnalyticEventCallbackmw.AnalyticEvent.CallbackinspectSelectorCountsmw.inspect.SelectorCountsResourceLoaderCSSReportmw.inspect.ResourceLoaderReport.CSSResourceLoaderSizeReportmw.inspect.ResourceLoaderReport.SizeResourceLoaderStoreReportmw.inspect.ResourceLoaderReport.StoreResourceLoaderTimeReportmw.inspect.ResourceLoaderReport.TimeResourceLoaderTimeReportmw.inspect.ResourceLoaderReport.TimeResourceLoaderReportmw.inspect.ResourceLoaderReportResourceLoaderReportMapmw.inspect.ResourceLoaderReportMapDependencymw.inspect.DependencyloaderModulemw.loader.ModuleModuleKeymw.loader.Module.KeyModuleStatemw.loader.Module.StateModuleMessagemw.loader.Module.MessageModuleStylemw.loader.Module.StyleModuleTemplatesmw.loader.Module.TemplatesModuleDeclaratormw.loader.Module.DeclaratorModuleRequiremw.loader.Module.RequireModuleScriptmw.loader.Module.ScriptModuleRegistryEntrymw.loader.Module.RegistryEntryJsonModuleStoremw.loader.store.JsonResourceLoaderStoreStatsmw.loader.store.StatsMapTypeOrArraymw.TypeOrArrayGetOrDefaultmw.GetOrDefaultPickOrDefaultmw.PickOrDefaultExtensibleMapmw.Map.ExtensiblenotificationNotificationmw.notification.Notificationmw.notification.NotificationOptionsmw.notification.Notification.OptionsRestRestResponsemw.Rest.ResponsesearchSuggestResponseFunctionmw.searchSuggest.ResponseFunctionResponseMetaDatamw.searchSuggest.ResponseMetaDatastorageSafeStoragemw.SafeStorageMwStoragemw.StoragetemplateTemplateRenderermw.template.RendererTemplateCompilermw.template.CompilerTitleTitleLikemw.Title.LikeTitleExistenceStoremw.Title.ExistenceStoreUserInputOptionsmw.Title.UserInputOptionsUriQueryParamsmw.QueryParamsUriParsermw.Uri.Parsermw.Uri.UriOptionsmw.Uri.OptionsUserUserTokensmw.user.TokensUsermw.user.UserutilNoReturnmw.NoReturnResizeableThumbnailUrlmw.util.ResizeableThumbnailUrl