Merge pull request #12736 from simonseyock/onsignature-return

OnSignatures return more specific type
This commit is contained in:
Tim Schaub
2021-09-10 08:33:47 -06:00
committed by GitHub
28 changed files with 73 additions and 75 deletions

View File

@@ -81,12 +81,12 @@ class Collection extends BaseObject {
super();
/***
* @type {CollectionOnSignature<import("./Observable.js").OnReturn>}
* @type {CollectionOnSignature<import("./events").EventsKey>}
*/
this.on;
/***
* @type {CollectionOnSignature<import("./Observable.js").OnReturn>}
* @type {CollectionOnSignature<import("./events").EventsKey>}
*/
this.once;

View File

@@ -83,12 +83,12 @@ class Feature extends BaseObject {
super();
/***
* @type {FeatureOnSignature<import("./Observable.js").OnReturn>}
* @type {FeatureOnSignature<import("./events").EventsKey>}
*/
this.on;
/***
* @type {FeatureOnSignature<import("./Observable.js").OnReturn>}
* @type {FeatureOnSignature<import("./events").EventsKey>}
*/
this.once;

View File

@@ -107,12 +107,12 @@ class Geolocation extends BaseObject {
super();
/***
* @type {GeolocationOnSignature<import("./Observable.js").OnReturn>}
* @type {GeolocationOnSignature<import("./events").EventsKey>}
*/
this.on;
/***
* @type {GeolocationOnSignature<import("./Observable.js").OnReturn>}
* @type {GeolocationOnSignature<import("./events").EventsKey>}
*/
this.once;

View File

@@ -95,12 +95,12 @@ class BaseObject extends Observable {
super();
/***
* @type {ObjectOnSignature<import("./Observable.js").OnReturn>}
* @type {ObjectOnSignature<import("./events").EventsKey>}
*/
this.on;
/***
* @type {ObjectOnSignature<import("./Observable.js").OnReturn>}
* @type {ObjectOnSignature<import("./events").EventsKey>}
*/
this.once;

View File

@@ -9,23 +9,24 @@ import {listen, listenOnce, unlistenByKey} from './events.js';
* @template {string} Type
* @template {Event|import("./events/Event.js").default} EventClass
* @template Return
* @typedef {(type: Type|Type[], listener: (event: EventClass) => ?) => Return} OnSignature
* @typedef {(type: Type, listener: (event: EventClass) => ?) => Return} OnSignature
*/
/***
* @template {string} Type
* @template Return
* @typedef {(type: Type[], listener: (event: Event|import("./events/Event").default) => ?) => Return} CombinedOnSignature
*/
/***
* @typedef {import("./events").EventsKey|Array<import("./events").EventsKey>} OnReturn
* @typedef {(type: Type[], listener: (event: Event|import("./events/Event").default) => ?) => Return extends void ? void : Return[]} CombinedOnSignature
*/
/**
* @typedef {'change'|'error'} EventTypes
*/
/***
* @template Return
* @typedef {OnSignature<EventTypes, import("./events/Event.js").default, Return> & CombinedOnSignature<EventTypes, Return>} ObservableOnSignature
*/
/**
* @classdesc
* Abstract base class; normally only used for creating subclasses and not
@@ -41,20 +42,17 @@ class Observable extends EventTarget {
constructor() {
super();
/***
* @type {OnSignature<EventTypes, import("./events/Event.js").default, OnReturn>}
*/
this.on = this.onInternal;
this.on =
/** @type {ObservableOnSignature<import("./events").EventsKey>} */ (
this.onInternal
);
/***
* @type {OnSignature<EventTypes, import("./events/Event.js").default, OnReturn>}
*/
this.once = this.onceInternal;
this.once =
/** @type {ObservableOnSignature<import("./events").EventsKey>} */ (
this.onceInternal
);
/***
* @type {OnSignature<EventTypes, import("./events/Event.js").default, void>}
*/
this.un = this.unInternal;
this.un = /** @type {ObservableOnSignature<void>} */ (this.unInternal);
/**
* @private
@@ -84,7 +82,7 @@ class Observable extends EventTarget {
/**
* @param {string|Array<string>} type Type.
* @param {function(?): ?} listener Listener.
* @param {function((Event|import("./events/Event").default)): ?} listener Listener.
* @return {import("./events.js").EventsKey|Array<import("./events.js").EventsKey>} Event key.
* @protected
*/
@@ -103,7 +101,7 @@ class Observable extends EventTarget {
/**
* @param {string|Array<string>} type Type.
* @param {function(?): ?} listener Listener.
* @param {function((Event|import("./events/Event").default)): ?} listener Listener.
* @return {import("./events.js").EventsKey|Array<import("./events.js").EventsKey>} Event key.
* @protected
*/
@@ -125,7 +123,7 @@ class Observable extends EventTarget {
/**
* Unlisten for a certain type of event.
* @param {string|Array<string>} type Type.
* @param {function(?): ?} listener Listener.
* @param {function((Event|import("./events/Event").default)): ?} listener Listener.
* @protected
*/
unInternal(type, listener) {

View File

@@ -123,12 +123,12 @@ class Overlay extends BaseObject {
super();
/***
* @type {OverlayOnSignature<import("./Observable").OnReturn>}
* @type {OverlayOnSignature<import("./events").EventsKey>}
*/
this.on;
/***
* @type {OverlayOnSignature<import("./Observable").OnReturn>}
* @type {OverlayOnSignature<import("./events").EventsKey>}
*/
this.once;

View File

@@ -158,12 +158,12 @@ class PluggableMap extends BaseObject {
super();
/***
* @type {PluggableMapOnSignature<import("./Observable.js").OnReturn>}
* @type {PluggableMapOnSignature<import("./events").EventsKey>}
*/
this.on;
/***
* @type {PluggableMapOnSignature<import("./Observable.js").OnReturn>}
* @type {PluggableMapOnSignature<import("./events").EventsKey>}
*/
this.once;

View File

@@ -309,12 +309,12 @@ class View extends BaseObject {
super();
/***
* @type {ViewOnSignature<import("./Observable.js").OnReturn>}
* @type {ViewOnSignature<import("./events").EventsKey>}
*/
this.on;
/***
* @type {ViewOnSignature<import("./Observable.js").OnReturn>}
* @type {ViewOnSignature<import("./events").EventsKey>}
*/
this.once;

View File

@@ -90,12 +90,12 @@ class FullScreen extends Control {
});
/***
* @type {FullScreenOnSignature<import("../Observable.js").OnReturn>}
* @type {FullScreenOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {FullScreenOnSignature<import("../Observable.js").OnReturn>}
* @type {FullScreenOnSignature<import("../events").EventsKey>}
*/
this.once;

View File

@@ -80,12 +80,12 @@ class MousePosition extends Control {
});
/***
* @type {MousePositionOnSignature<import("../Observable.js").OnReturn>}
* @type {MousePositionOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {MousePositionOnSignature<import("../Observable.js").OnReturn>}
* @type {MousePositionOnSignature<import("../events").EventsKey>}
*/
this.once;

View File

@@ -100,12 +100,12 @@ class ScaleLine extends Control {
});
/***
* @type {ScaleLineOnSignature<import("../Observable.js").OnReturn>}
* @type {ScaleLineOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {ScaleLineOnSignature<import("../Observable.js").OnReturn>}
* @type {ScaleLineOnSignature<import("../events").EventsKey>}
*/
this.once;

View File

@@ -108,12 +108,12 @@ class DragAndDrop extends Interaction {
});
/***
* @type {DragAndDropOnSignature<import("../Observable").OnReturn>}
* @type {DragAndDropOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {DragAndDropOnSignature<import("../Observable").OnReturn>}
* @type {DragAndDropOnSignature<import("../events").EventsKey>}
*/
this.once;

View File

@@ -123,12 +123,12 @@ class DragBox extends PointerInteraction {
super();
/***
* @type {DragBoxOnSignature<import("../Observable").OnReturn>}
* @type {DragBoxOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {DragBoxOnSignature<import("../Observable").OnReturn>}
* @type {DragBoxOnSignature<import("../events").EventsKey>}
*/
this.once;

View File

@@ -204,12 +204,12 @@ class Draw extends PointerInteraction {
super(pointerOptions);
/***
* @type {DrawOnSignature<import("../Observable").OnReturn>}
* @type {DrawOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {DrawOnSignature<import("../Observable").OnReturn>}
* @type {DrawOnSignature<import("../events").EventsKey>}
*/
this.once;

View File

@@ -103,12 +103,12 @@ class Extent extends PointerInteraction {
super(/** @type {import("./Pointer.js").Options} */ (options));
/***
* @type {ExtentOnSignature<import("../Observable.js").OnReturn>}
* @type {ExtentOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {ExtentOnSignature<import("../Observable.js").OnReturn>}
* @type {ExtentOnSignature<import("../events").EventsKey>}
*/
this.once;

View File

@@ -46,12 +46,12 @@ class Interaction extends BaseObject {
super();
/***
* @type {InteractionOnSignature<import("../Observable.js").OnReturn>}
* @type {InteractionOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {InteractionOnSignature<import("../Observable.js").OnReturn>}
* @type {InteractionOnSignature<import("../events").EventsKey>}
*/
this.once;

View File

@@ -203,12 +203,12 @@ class Modify extends PointerInteraction {
super(/** @type {import("./Pointer.js").Options} */ (options));
/***
* @type {ModifyOnSignature<import("../Observable.js").OnReturn>}
* @type {ModifyOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {ModifyOnSignature<import("../Observable.js").OnReturn>}
* @type {ModifyOnSignature<import("../events").EventsKey>}
*/
this.once;

View File

@@ -167,12 +167,12 @@ class Select extends Interaction {
super();
/***
* @type {SelectOnSignature<import("../Observable.js").OnReturn>}
* @type {SelectOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {SelectOnSignature<import("../Observable.js").OnReturn>}
* @type {SelectOnSignature<import("../events").EventsKey>}
*/
this.once;

View File

@@ -140,12 +140,12 @@ class Translate extends PointerInteraction {
super(/** @type {import("./Pointer.js").Options} */ (options));
/***
* @type {TranslateOnSignature<import("../Observable.js").OnReturn>}
* @type {TranslateOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {TranslateOnSignature<import("../Observable.js").OnReturn>}
* @type {TranslateOnSignature<import("../events").EventsKey>}
*/
this.once;

View File

@@ -60,12 +60,12 @@ class BaseLayer extends BaseObject {
super();
/***
* @type {BaseLayerOnSignature<import("../Observable.js").OnReturn>}
* @type {BaseLayerOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {BaseLayerOnSignature<import("../Observable.js").OnReturn>}
* @type {BaseLayerOnSignature<import("../events").EventsKey>}
*/
this.once;

View File

@@ -72,12 +72,12 @@ class BaseTileLayer extends Layer {
super(baseOptions);
/***
* @type {BaseTileLayerOnSignature<import("../Observable.js").OnReturn>}
* @type {BaseTileLayerOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {BaseTileLayerOnSignature<import("../Observable.js").OnReturn>}
* @type {BaseTileLayerOnSignature<import("../events").EventsKey>}
*/
this.once;

View File

@@ -73,12 +73,12 @@ class LayerGroup extends BaseLayer {
super(baseOptions);
/***
* @type {GroupOnSignature<import("../Observable.js").OnReturn>}
* @type {GroupOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {GroupOnSignature<import("../Observable.js").OnReturn>}
* @type {GroupOnSignature<import("../events").EventsKey>}
*/
this.once;

View File

@@ -107,12 +107,12 @@ class Layer extends BaseLayer {
super(baseOptions);
/***
* @type {LayerOnSignature<import("../Observable.js").OnReturn>}
* @type {LayerOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {LayerOnSignature<import("../Observable.js").OnReturn>}
* @type {LayerOnSignature<import("../events").EventsKey>}
*/
this.once;

View File

@@ -106,12 +106,12 @@ class VectorTileLayer extends BaseVectorLayer {
);
/***
* @type {VectorTileLayerOnSignature<import("../Observable.js").OnReturn>}
* @type {VectorTileLayerOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {VectorTileLayerOnSignature<import("../Observable.js").OnReturn>}
* @type {VectorTileLayerOnSignature<import("../events").EventsKey>}
*/
this.once;

View File

@@ -103,12 +103,12 @@ class ImageSource extends Source {
});
/***
* @type {ImageSourceOnSignature<import("../Observable.js").OnReturn>}
* @type {ImageSourceOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {ImageSourceOnSignature<import("../Observable.js").OnReturn>}
* @type {ImageSourceOnSignature<import("../events").EventsKey>}
*/
this.once;

View File

@@ -548,12 +548,12 @@ class RasterSource extends ImageSource {
});
/***
* @type {RasterSourceOnSignature<import("../Observable.js").OnReturn>}
* @type {RasterSourceOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {RasterSourceOnSignature<import("../Observable.js").OnReturn>}
* @type {RasterSourceOnSignature<import("../events").EventsKey>}
*/
this.once;

View File

@@ -62,12 +62,12 @@ class TileSource extends Source {
});
/***
* @type {TileSourceOnSignature<import("../Observable.js").OnReturn>}
* @type {TileSourceOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {TileSourceOnSignature<import("../Observable.js").OnReturn>}
* @type {TileSourceOnSignature<import("../events").EventsKey>}
*/
this.once;

View File

@@ -187,12 +187,12 @@ class VectorSource extends Source {
});
/***
* @type {VectorSourceOnSignature<import("../Observable.js").OnReturn>}
* @type {VectorSourceOnSignature<import("../events").EventsKey>}
*/
this.on;
/***
* @type {VectorSourceOnSignature<import("../Observable.js").OnReturn>}
* @type {VectorSourceOnSignature<import("../events").EventsKey>}
*/
this.once;