##// END OF EJS Templates
added type parameter to Evented<T>, T is the event map...
cin -
r10:641c326d4bb4 v1.0.2 default
parent child
Show More
@@ -0,0 +1,16
1 import * as Evented from "dojo/Evented";
2
3 interface DoorEvents {
4 open: { authorized: boolean }
5 close: void
6 }
7
8 const door = new Evented<DoorEvents>();
9
10 door.on("open", evt => evt.authorized);
11
12 door.on<any>("location-change", (x,y,z) => x+y+z);
13
14 door.emit("open", { authorized: false });
15 door.emit("close");
16 door.emit<any>("location-change");
@@ -39,7 +39,11 typescript {
39
39
40 configureTsTest {
40 configureTsTest {
41 compilerOptions {
41 compilerOptions {
42 types = ["../main/typings/dojo/modules","../main/typings/dijit/modules"]
42 types = [
43 "../main/typings/dojo/modules",
44 "../main/typings/dijit/modules",
45 "../main/typings/dojo/NodeList-fx"
46 ]
43 module = "ESNext"
47 module = "ESNext"
44 it.target = "ESNext"
48 it.target = "ESNext"
45 }
49 }
@@ -549,10 +549,6 declare namespace dijit {
549 onClose(): boolean;
549 onClose(): boolean;
550 }
550 }
551
551
552 type Props<T> = {
553 [k in Exclude<keyof T, keyof object>] : T[k] extends (...args: any) => any ? never: k;
554 }[ keyof T];
555
556 interface _WidgetBase {
552 interface _WidgetBase {
557 /**
553 /**
558 * Used across all instances a hash to cache attribute names and their getter
554 * Used across all instances a hash to cache attribute names and their getter
@@ -603,7 +599,7 declare namespace dijit {
603 * Watches a property for changes
599 * Watches a property for changes
604 */
600 */
605 watch(callback: <K extends keyof any>(prop: K, oldValue: any, newValue: any) => void): dojo.WatchHandle;
601 watch(callback: <K extends keyof any>(prop: K, oldValue: any, newValue: any) => void): dojo.WatchHandle;
606 watch<K extends Props<this>>(name: K, callback: (prop: K, oldValue: this[K], newValue: this[K]) => void): dojo.WatchHandle;
602 watch<K extends keyof this>(name: K, callback: (prop: K, oldValue: this[K], newValue: this[K]) => void): dojo.WatchHandle;
607 }
603 }
608
604
609 type EventInitArgs<T extends Event> = {
605 type EventInitArgs<T extends Event> = {
@@ -771,25 +767,14 declare namespace dijit {
771 * Used by widgets to signal that a synthetic event occurred, ex:
767 * Used by widgets to signal that a synthetic event occurred, ex:
772 * | myWidget.emit("attrmodified-selectedChildWidget", {}).
768 * | myWidget.emit("attrmodified-selectedChildWidget", {}).
773 */
769 */
774 emit<K extends keyof Events>(eventName: K, evt: EventInitArgs<Events[K]>): void;
770 emit<K extends keyof Events>(eventName: K, evt: EventInitArgs<Events[K]>, callbackArgs?: any[]): any;
775
776 /**
777 * @param type
778 * @param eventObj
779 * @param callbackArgs
780 */
781 emit<K extends string>(
782 type: K,
783 eventObj?: K extends keyof Events ? EventInitArgs<Events[K]> : any,
784 callbackArgs?: any[]
785 ): any;
786
771
787 /**
772 /**
788 * Call specified function when event occurs, ex: myWidget.on("click", function(){ ... }).
773 * Call specified function when event occurs, ex: myWidget.on("click", function(){ ... }).
789 */
774 */
790 on<K extends keyof Events>(eventName: K, cb: (evt: Events[K]) => void): dojo.WatchHandle;
775 on<K extends keyof Events>(eventName: K, cb: (evt: Events[K]) => void): dojo.WatchHandle;
791
776
792 on(type: string | dojo.ExtensionEvent, func: dojo.EventListener | Function): dojo.WatchHandle;
777 on(type: dojo.ExtensionEvent, func: dojo.EventListener): dojo.WatchHandle;
793
778
794 /**
779 /**
795 * Returns a string that represents the widget.
780 * Returns a string that represents the widget.
@@ -455,6 +455,8 declare namespace dijit {
455
455
456 startup(): void;
456 startup(): void;
457 destroy(preserveDom?: boolean): void;
457 destroy(preserveDom?: boolean): void;
458
459 _setValueAttr(value: any): void;
458 }
460 }
459
461
460 interface _FormMixinConstructor extends dojo._base.DeclareConstructor<_FormMixin> { }
462 interface _FormMixinConstructor extends dojo._base.DeclareConstructor<_FormMixin> { }
@@ -239,7 +239,7 declare namespace dojo {
239 /**
239 /**
240 * number of decimal places to show. Default is defined based on which currency is used.
240 * number of decimal places to show. Default is defined based on which currency is used.
241 */
241 */
242 places?: number;
242 places?: string | number;
243 }
243 }
244
244
245 interface CurrencyParseOptions extends NumberParseOptions {
245 interface CurrencyParseOptions extends NumberParseOptions {
@@ -264,7 +264,7 declare namespace dojo {
264 /**
264 /**
265 * number of decimal places to show. Default is defined based on which currency is used.
265 * number of decimal places to show. Default is defined based on which currency is used.
266 */
266 */
267 places?: number;
267 places?: number | string;
268
268
269 /**
269 /**
270 * Whether to include the fractional portion, where the number of decimal places are implied by the currency
270 * Whether to include the fractional portion, where the number of decimal places are implied by the currency
@@ -783,13 +783,17 declare namespace dojo {
783
783
784 /* dojo/Evented */
784 /* dojo/Evented */
785
785
786 interface Evented {
786 interface Evented<EM extends { [e in string]: any; } = any> {
787 on(type: string | ExtensionEvent, listener: EventListener | Function): Handle;
787 on<E extends keyof EM>(type: E, listener: (this: this, ...args: EM[E] extends any[] ? EM[E]: [EM[E]]) => void ): Handle;
788 emit(type: string | ExtensionEvent, ...events: any[]): boolean;
788
789 on(type: ExtensionEvent, listener: (...args: any[]) => void): Handle;
790
791 emit<E extends keyof EM>(type: E, ...args: EM[E] extends any[] ? EM[E] : [EM[E]] );
792 emit(type: ExtensionEvent, ...events: any[]): boolean;
789 }
793 }
790
794
791 interface EventedConstructor extends _base.DeclareConstructor<Evented> {
795 interface EventedConstructor extends _base.DeclareConstructor<Evented> {
792 new (params?: Object): Evented;
796 new <T>(params?: Object): Evented<T>;
793 }
797 }
794
798
795 /* dojo/fx */
799 /* dojo/fx */
@@ -1238,7 +1242,7 declare namespace dojo {
1238 * fixed number of decimal places to show. This overrides any
1242 * fixed number of decimal places to show. This overrides any
1239 * information in the provided pattern.
1243 * information in the provided pattern.
1240 */
1244 */
1241 places?: number;
1245 places?: number | string;
1242
1246
1243 /**
1247 /**
1244 * 5 rounds to nearest .5; 0 rounds to nearest whole (default). -1
1248 * 5 rounds to nearest .5; 0 rounds to nearest whole (default). -1
@@ -1353,7 +1357,7 declare namespace dojo {
1353 * not given, the decimal part is optional and the number of places is
1357 * not given, the decimal part is optional and the number of places is
1354 * unlimited.
1358 * unlimited.
1355 */
1359 */
1356 places?: number;
1360 places?: number | string;
1357
1361
1358 /**
1362 /**
1359 * A string for the character used as the decimal point. Default
1363 * A string for the character used as the decimal point. Default
@@ -420,7 +420,7 declare module 'dojo/errors/RequestTimeo
420 }
420 }
421
421
422 declare module 'dojo/Evented' {
422 declare module 'dojo/Evented' {
423 type Evented = dojo.Evented;
423 type Evented<T> = dojo.Evented<T>;
424 const Evented: dojo.EventedConstructor;
424 const Evented: dojo.EventedConstructor;
425 export = Evented;
425 export = Evented;
426 }
426 }
@@ -1,6 +1,6
1 import "dojo/NodeList-fx";
1 import * as NodeList from "dojo/NodeList-fx";
2
2
3 declare const nl: dojo.NodeList<Node>;
3 const nl: dojo.NodeList<Node> = new NodeList();
4
4
5 const anim: dojo._base.Animation = nl.fadeIn();
5 const anim: dojo._base.Animation = nl.fadeIn();
6 const anim2: dojo._base.Animation = nl.fadeIn({duration: 500});
6 const anim2: dojo._base.Animation = nl.fadeIn({duration: 500});
@@ -53,7 +53,7 w.emit("click", {} );
53
53
54 w.emit("click", {} );
54 w.emit("click", {} );
55
55
56 w.emit("some-extra-event", {});
56 w.emit<any>("some-extra-event", {});
57
57
58 w.on("click", e => e);
58 w.on("click", e => e);
59 w.on("some-extra-event", e => e);
59 w.on<any>("some-extra-event", e => e);
General Comments 0
You need to be logged in to leave comments. Login now