From c1295d24ee35d2e5254a6f8e73f921fcaabab045 Mon Sep 17 00:00:00 2001 From: Olivier Sechet Date: Thu, 8 Mar 2018 07:25:27 +0100 Subject: [PATCH] Fix ban-type lint --- types/openlayers/index.d.ts | 17 ++++++++++------- types/openlayers/openlayers-tests.ts | 17 +++++++++-------- types/openlayers/tslint.json | 2 -- 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/types/openlayers/index.d.ts b/types/openlayers/index.d.ts index 333ee0f621..09e22cce96 100644 --- a/types/openlayers/index.d.ts +++ b/types/openlayers/index.d.ts @@ -11,7 +11,7 @@ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // Definitions partially generated using tsd-jsdoc (https://github.com/englercj/tsd-jsdoc) -declare type GlobalObject = Object; +interface GlobalObject { [key: string]: any; } /** * @namespace ol @@ -1491,6 +1491,9 @@ declare module ol { } } + /* From ol/typedefs.js */ + type EventsListenerFunctionType = ((evt: ol.events.Event) => void) | ((evt: ol.events.Event) => boolean); + /** * @namespace ol.extent */ @@ -7957,7 +7960,7 @@ declare module ol { * will be an array of keys. * @api stable */ - on(type: (string | string[]), listener: Function, opt_this?: GlobalObject): (ol.EventsKey | ol.EventsKey[]); + on(type: (string | string[]), listener: ol.EventsListenerFunctionType, opt_this?: GlobalObject): (ol.EventsKey | ol.EventsKey[]); /** * Listen once for a certain type of event. @@ -7969,7 +7972,7 @@ declare module ol { * will be an array of keys. * @api stable */ - once(type: (string | string[]), listener: Function, opt_this?: GlobalObject): (ol.EventsKey | ol.EventsKey[]); + once(type: (string | string[]), listener: ol.EventsListenerFunctionType, opt_this?: GlobalObject): (ol.EventsKey | ol.EventsKey[]); /** * Unlisten for a certain type of event. @@ -7979,7 +7982,7 @@ declare module ol { * `listener`. * @api stable */ - un(type: (string | string[]), listener: Function, opt_this?: GlobalObject): void; + un(type: (string | string[]), listener: ol.EventsListenerFunctionType, opt_this?: GlobalObject): void; } /** @@ -11694,7 +11697,7 @@ declare module ol { * target: (EventTarget|ol.events.EventTarget), * type: string}} */ - type EventsKey = Object; + type EventsKey = GlobalObject; /** * An array of numbers representing an extent: `[minx, miny, maxx, maxy]`. @@ -11995,7 +11998,7 @@ declare module ol { * @typedef {{numberOfFeatures: number, * bounds: ol.Extent}} */ - type WFSFeatureCollectionMetadata = Object; + type WFSFeatureCollectionMetadata = GlobalObject; /** * Total deleted; total inserted; total updated; array of insert ids. @@ -12004,7 +12007,7 @@ declare module ol { * totalUpdated: number, * insertIds: Array.}} */ - type WFSTransactionResponse = Object; + type WFSTransactionResponse = GlobalObject; /** * @constructor diff --git a/types/openlayers/openlayers-tests.ts b/types/openlayers/openlayers-tests.ts index ce13ae8385..3941345625 100644 --- a/types/openlayers/openlayers-tests.ts +++ b/types/openlayers/openlayers-tests.ts @@ -6,8 +6,9 @@ let stringValue: string; let stringArray: string[]; let jsonValue: JSON; let domEventTarget: EventTarget; -let fn: Function; -let object: Object; +let listener: ol.EventsListenerFunctionType; +let object: { [key: string]: any }; +let fn: () => void; // Callback predefinitions for OpenLayers let preRenderFunction: ol.PreRenderFunction; @@ -579,12 +580,12 @@ observable.dispatchEvent({ type: stringValue, a: numberValue, b: stringValue, c: observable.dispatchEvent(olEvent); observable.dispatchEvent(stringValue); numberValue = observable.getRevision(); -eventKeyMixed = observable.on(stringValue, fn); -eventKeyMixed = observable.on([stringValue, stringValue], fn, {}); -eventKeyMixed = observable.once(stringValue, fn); -eventKeyMixed = observable.once([stringValue, stringValue], fn, {}); -observable.un(stringValue, fn); -observable.un([stringValue, stringValue], fn, {}); +eventKeyMixed = observable.on(stringValue, listener); +eventKeyMixed = observable.on([stringValue, stringValue], listener, {}); +eventKeyMixed = observable.once(stringValue, listener); +eventKeyMixed = observable.once([stringValue, stringValue], listener, {}); +observable.un(stringValue, listener); +observable.un([stringValue, stringValue], listener, {}); // // ol.proj diff --git a/types/openlayers/tslint.json b/types/openlayers/tslint.json index 2effdd6100..d44bbdd733 100644 --- a/types/openlayers/tslint.json +++ b/types/openlayers/tslint.json @@ -1,8 +1,6 @@ { "extends": "dtslint/dt.json", "rules": { - // It appears somewhat difficult to remove the Function and Object types - "ban-types": false, // This currently fails for an option that does not appear to be in OL 4 "no-any-union": false, // Not sure how to work around this, or if it's necessary to