# HG changeset patch # User cin # Date 2021-11-18 13:54:10 # Node ID 641c326d4bb40f5af079c6944f085f06e8305c2c # Parent 26f5ab96b7299220800df78c885a37a312a43b73 added type parameter to Evented, T is the event map _WidgetBase emit() and on() are now more strict, they accept only valid event names, or explicit `any` added _setValueAttr method to _FormMixin diff --git a/dojo-typings/build.gradle b/dojo-typings/build.gradle --- a/dojo-typings/build.gradle +++ b/dojo-typings/build.gradle @@ -39,7 +39,11 @@ typescript { configureTsTest { compilerOptions { - types = ["../main/typings/dojo/modules","../main/typings/dijit/modules"] + types = [ + "../main/typings/dojo/modules", + "../main/typings/dijit/modules", + "../main/typings/dojo/NodeList-fx" + ] module = "ESNext" it.target = "ESNext" } diff --git a/dojo-typings/src/main/typings/dijit/dijit.d.ts b/dojo-typings/src/main/typings/dijit/dijit.d.ts --- a/dojo-typings/src/main/typings/dijit/dijit.d.ts +++ b/dojo-typings/src/main/typings/dijit/dijit.d.ts @@ -549,10 +549,6 @@ declare namespace dijit { onClose(): boolean; } - type Props = { - [k in Exclude] : T[k] extends (...args: any) => any ? never: k; - }[ keyof T]; - interface _WidgetBase { /** * Used across all instances a hash to cache attribute names and their getter @@ -603,7 +599,7 @@ declare namespace dijit { * Watches a property for changes */ watch(callback: (prop: K, oldValue: any, newValue: any) => void): dojo.WatchHandle; - watch>(name: K, callback: (prop: K, oldValue: this[K], newValue: this[K]) => void): dojo.WatchHandle; + watch(name: K, callback: (prop: K, oldValue: this[K], newValue: this[K]) => void): dojo.WatchHandle; } type EventInitArgs = { @@ -771,25 +767,14 @@ declare namespace dijit { * Used by widgets to signal that a synthetic event occurred, ex: * | myWidget.emit("attrmodified-selectedChildWidget", {}). */ - emit(eventName: K, evt: EventInitArgs): void; - - /** - * @param type - * @param eventObj - * @param callbackArgs - */ - emit( - type: K, - eventObj?: K extends keyof Events ? EventInitArgs : any, - callbackArgs?: any[] - ): any; + emit(eventName: K, evt: EventInitArgs, callbackArgs?: any[]): any; /** * Call specified function when event occurs, ex: myWidget.on("click", function(){ ... }). */ on(eventName: K, cb: (evt: Events[K]) => void): dojo.WatchHandle; - on(type: string | dojo.ExtensionEvent, func: dojo.EventListener | Function): dojo.WatchHandle; + on(type: dojo.ExtensionEvent, func: dojo.EventListener): dojo.WatchHandle; /** * Returns a string that represents the widget. diff --git a/dojo-typings/src/main/typings/dijit/form.d.ts b/dojo-typings/src/main/typings/dijit/form.d.ts --- a/dojo-typings/src/main/typings/dijit/form.d.ts +++ b/dojo-typings/src/main/typings/dijit/form.d.ts @@ -455,6 +455,8 @@ declare namespace dijit { startup(): void; destroy(preserveDom?: boolean): void; + + _setValueAttr(value: any): void; } interface _FormMixinConstructor extends dojo._base.DeclareConstructor<_FormMixin> { } diff --git a/dojo-typings/src/main/typings/dojo/dojo.d.ts b/dojo-typings/src/main/typings/dojo/dojo.d.ts --- a/dojo-typings/src/main/typings/dojo/dojo.d.ts +++ b/dojo-typings/src/main/typings/dojo/dojo.d.ts @@ -239,7 +239,7 @@ declare namespace dojo { /** * number of decimal places to show. Default is defined based on which currency is used. */ - places?: number; + places?: string | number; } interface CurrencyParseOptions extends NumberParseOptions { @@ -264,7 +264,7 @@ declare namespace dojo { /** * number of decimal places to show. Default is defined based on which currency is used. */ - places?: number; + places?: number | string; /** * Whether to include the fractional portion, where the number of decimal places are implied by the currency @@ -783,13 +783,17 @@ declare namespace dojo { /* dojo/Evented */ - interface Evented { - on(type: string | ExtensionEvent, listener: EventListener | Function): Handle; - emit(type: string | ExtensionEvent, ...events: any[]): boolean; + interface Evented { + on(type: E, listener: (this: this, ...args: EM[E] extends any[] ? EM[E]: [EM[E]]) => void ): Handle; + + on(type: ExtensionEvent, listener: (...args: any[]) => void): Handle; + + emit(type: E, ...args: EM[E] extends any[] ? EM[E] : [EM[E]] ); + emit(type: ExtensionEvent, ...events: any[]): boolean; } interface EventedConstructor extends _base.DeclareConstructor { - new (params?: Object): Evented; + new (params?: Object): Evented; } /* dojo/fx */ @@ -1238,7 +1242,7 @@ declare namespace dojo { * fixed number of decimal places to show. This overrides any * information in the provided pattern. */ - places?: number; + places?: number | string; /** * 5 rounds to nearest .5; 0 rounds to nearest whole (default). -1 @@ -1353,7 +1357,7 @@ declare namespace dojo { * not given, the decimal part is optional and the number of places is * unlimited. */ - places?: number; + places?: number | string; /** * A string for the character used as the decimal point. Default diff --git a/dojo-typings/src/main/typings/dojo/modules.d.ts b/dojo-typings/src/main/typings/dojo/modules.d.ts --- a/dojo-typings/src/main/typings/dojo/modules.d.ts +++ b/dojo-typings/src/main/typings/dojo/modules.d.ts @@ -420,7 +420,7 @@ declare module 'dojo/errors/RequestTimeo } declare module 'dojo/Evented' { - type Evented = dojo.Evented; + type Evented = dojo.Evented; const Evented: dojo.EventedConstructor; export = Evented; } diff --git a/dojo-typings/src/test/ts/EventedTests.ts b/dojo-typings/src/test/ts/EventedTests.ts new file mode 100644 --- /dev/null +++ b/dojo-typings/src/test/ts/EventedTests.ts @@ -0,0 +1,16 @@ +import * as Evented from "dojo/Evented"; + +interface DoorEvents { + open: { authorized: boolean } + close: void +} + +const door = new Evented(); + +door.on("open", evt => evt.authorized); + +door.on("location-change", (x,y,z) => x+y+z); + +door.emit("open", { authorized: false }); +door.emit("close"); +door.emit("location-change"); diff --git a/dojo-typings/src/test/ts/NodeListFxTests.ts b/dojo-typings/src/test/ts/NodeListFxTests.ts --- a/dojo-typings/src/test/ts/NodeListFxTests.ts +++ b/dojo-typings/src/test/ts/NodeListFxTests.ts @@ -1,6 +1,6 @@ -import "dojo/NodeList-fx"; +import * as NodeList from "dojo/NodeList-fx"; -declare const nl: dojo.NodeList; +const nl: dojo.NodeList = new NodeList(); const anim: dojo._base.Animation = nl.fadeIn(); const anim2: dojo._base.Animation = nl.fadeIn({duration: 500}); diff --git a/dojo-typings/src/test/ts/_WidgetTests.ts b/dojo-typings/src/test/ts/_WidgetTests.ts --- a/dojo-typings/src/test/ts/_WidgetTests.ts +++ b/dojo-typings/src/test/ts/_WidgetTests.ts @@ -53,7 +53,7 @@ w.emit("click", {} ); w.emit("click", {} ); -w.emit("some-extra-event", {}); +w.emit("some-extra-event", {}); w.on("click", e => e); -w.on("some-extra-event", e => e); +w.on("some-extra-event", e => e);