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,9 @@ typescript { configureTsTest { compilerOptions { - types = ["../main/typings/dojo/modules","../main/typings/dijit/modules"]; + types = ["../main/typings/dojo/modules","../main/typings/dijit/modules"] + 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,6 +549,10 @@ declare namespace dijit { onClose(): boolean; } + type Props<T> = { + [k in Exclude<keyof T, keyof object>] : 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 @@ -569,7 +573,7 @@ declare namespace dijit { */ _changeAttrValue(name: string, value: any): this; - get<K extends keyof this & string>(name: K): this[K]; + get<K extends keyof this>(name: K): this[K]; /** * Helper function to set new value for specified property, and call handlers @@ -591,15 +595,15 @@ declare namespace dijit { /** * Set a property on a Stateful instance */ - set<K extends keyof this & string>(name: K, value: this[K]): this; - set<K extends { [p in keyof this]: this[p] extends any[] ? p : never; }[keyof this & string]>(name: K, ...values: this[K]): this; - set(values: Partial<this>): this; + set<K extends keyof this>(name: K, value: this[K]): this; + set<K extends keyof this, V extends this[K] & any[]>(name: K, ...values: V): this; + set<K extends keyof this>(values: {[p in K]: this[p]}): this; /** * Watches a property for changes */ watch(callback: <K extends keyof any>(prop: K, oldValue: any, newValue: any) => void): dojo.WatchHandle; - watch<K extends keyof this>(name: K, callback: (prop: K, oldValue: this[K], newValue: this[K]) => void): dojo.WatchHandle; + watch<K extends Props<this>>(name: K, callback: (prop: K, oldValue: this[K], newValue: this[K]) => void): dojo.WatchHandle; } type EventInitArgs<T extends Event> = { 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 @@ -8,7 +8,7 @@ declare namespace dijit { [prop: string]: any; } - interface ConstrainedValueFunction<V, C extends Constraints, T> { + interface ConstrainedValueFunction<V = any, C extends Constraints = Constraints, T = any> { /** * Returns a value that has been constrained by the constraints * @param value The value to constrain @@ -18,7 +18,7 @@ declare namespace dijit { (value: V, constraints: C): T; } - interface ConstrainedValidFunction<C extends Constraints> { + interface ConstrainedValidFunction<C extends Constraints = Constraints> { /** * Returns true if the value is valid based on the constraints, otherwise * returns false. @@ -29,7 +29,7 @@ declare namespace dijit { (value: any, constraints: C): boolean; } - interface ConstraintsToRegExpString<C extends Constraints> { + interface ConstraintsToRegExpString<C extends Constraints = Constraints> { /** * Takes a set of constraints and returns a RegExpString that can be used * to match values against @@ -46,7 +46,7 @@ declare namespace dijit { /* dijit/form/_AutoCompleterMixin */ /* tslint:disable:class-name */ - interface _AutoCompleterMixin<T extends Object, Q extends dojo.store.api.BaseQueryType, O extends dojo.store.api.QueryOptions> extends _SearchMixin<T, Q, O> { + interface _AutoCompleterMixin<T extends Object = any, Q extends dojo.store.api.BaseQueryType = dojo.store.api.BaseQueryType, O extends dojo.store.api.QueryOptions = dojo.store.api.QueryOptions> extends _SearchMixin<T, Q, O> { /** * This is the item returned by the dojo/store/api/Store implementation that * provides the data for this ComboBox, it's the currently selected item. @@ -179,7 +179,7 @@ declare namespace dijit { /* dijit/form/_ComboBoxMenu */ - interface _ComboBoxMenu<T> extends _WidgetBase, _TemplatedMixin, _ListMouseMixin, _ComboBoxMenuMixin<T> { + interface _ComboBoxMenu<T = any> extends _WidgetBase, _TemplatedMixin, _ListMouseMixin, _ComboBoxMenuMixin<T> { templateString: string; baseClass: string; @@ -219,12 +219,12 @@ declare namespace dijit { } interface _ComboBoxMenuConstructor extends _WidgetBaseConstructor<_ComboBoxMenu<any>> { - new <T>(params: Object, srcNodeRef: dojo.NodeOrString): _ComboBoxMenu<T>; + new <T = any>(params: Object, srcNodeRef: dojo.NodeOrString): _ComboBoxMenu<T>; } /* dijit/form/_ComboBoxMenuMixin */ - interface _ComboBoxMenuMixin<T> { + interface _ComboBoxMenuMixin<T = any> { /** * Holds "next" and "previous" text for paging buttons on drop down */ @@ -468,7 +468,7 @@ declare namespace dijit { disabled?: boolean; } - interface _FormSelectWidget<T extends Object, Q extends dojo.store.api.BaseQueryType, O extends dojo.store.api.QueryOptions> extends _FormValueWidget { + interface _FormSelectWidget<T extends Object, Q extends dojo.store.api.BaseQueryType = dojo.store.api.BaseQueryType, O extends dojo.store.api.QueryOptions = dojo.store.api.QueryOptions> extends _FormValueWidget { /** * Whether or not we are multi-valued */ @@ -862,7 +862,7 @@ declare namespace dijit { /* dijit/form/_SearchMixin */ - interface _SearchMixin<T extends Object, Q extends dojo.store.api.BaseQueryType, O extends dojo.store.api.QueryOptions> { + interface _SearchMixin<T extends Object, Q extends dojo.store.api.BaseQueryType = dojo.store.api.BaseQueryType, O extends dojo.store.api.QueryOptions = dojo.store.api.QueryOptions> { /** * Argument to data provider. * Specifies maximum number of search results to return per query @@ -1006,7 +1006,7 @@ declare namespace dijit { /* dijit/form/_TextBoxMixin */ - interface _TextBoxMixin<C extends Constraints> { + interface _TextBoxMixin<C extends Constraints = Constraints> { /** * Removes leading and trailing whitespace if true. Default is false. */ @@ -1163,18 +1163,18 @@ declare namespace dijit { /* dijit/form/ComboBox */ - interface ComboBox<T extends Object, Q extends dojo.store.api.BaseQueryType, O extends dojo.store.api.QueryOptions, C extends Constraints> extends ValidationTextBox<C>, ComboBoxMixin<T, Q, O> { + interface ComboBox<T extends Object = any, Q extends dojo.store.api.BaseQueryType = dojo.store.api.BaseQueryType, O extends dojo.store.api.QueryOptions = dojo.store.api.QueryOptions, C extends Constraints = Constraints> extends ValidationTextBox<C>, ComboBoxMixin<T, Q, O> { // set(name: string, value: any): this; // set(values: Object): this; } - interface ComboBoxConstructor extends _WidgetBaseConstructor<ComboBox<any, any, any, any>> { - new <T extends Object, Q extends dojo.store.api.BaseQueryType, O extends dojo.store.api.QueryOptions, C extends Constraints>(params: Object, srcNodeRef: dojo.NodeOrString): ComboBox<T, Q, O, C>; + interface ComboBoxConstructor extends _WidgetBaseConstructor<ComboBox<any>> { + new <T extends Object = any, Q extends dojo.store.api.BaseQueryType = dojo.store.api.BaseQueryType, O extends dojo.store.api.QueryOptions = dojo.store.api.QueryOptions, C extends Constraints = Constraints>(params: Object, srcNodeRef: dojo.NodeOrString): ComboBox<T, Q, O, C>; } /* dijit/form/ComboBoxMixin */ - interface ComboBoxMixin<T extends Object, Q extends dojo.store.api.BaseQueryType, O extends dojo.store.api.QueryOptions> extends _HasDropDown<_ComboBoxMenu<T>>, _AutoCompleterMixin<T, Q, O> { + interface ComboBoxMixin<T extends Object = any, Q extends dojo.store.api.BaseQueryType = dojo.store.api.BaseQueryType, O extends dojo.store.api.QueryOptions = dojo.store.api.QueryOptions> extends _HasDropDown<_ComboBoxMenu<T>>, _AutoCompleterMixin<T, Q, O> { /** * Dropdown widget class used to select a date/time. @@ -1204,7 +1204,7 @@ declare namespace dijit { buildRendering(): void; } - interface ComboBoxMixinConstructor<T, U extends dojo.store.api.BaseQueryType, V> extends _WidgetBaseConstructor<ComboBoxMixin<T, U, V>> { } + interface ComboBoxMixinConstructor<T = any, U extends dojo.store.api.BaseQueryType = dojo.store.api.BaseQueryType, V = any> extends _WidgetBaseConstructor<ComboBoxMixin<T, U, V>> { } /* dijit/form/CurrencyTextBox */ @@ -1840,7 +1840,7 @@ declare namespace dijit { (isFocused?: boolean): boolean; } - interface ValidationTextBox<C extends Constraints> extends TextBox { + interface ValidationTextBox<C extends Constraints = Constraints> extends TextBox { templateString: string; required: boolean; promptMessage: string; diff --git a/dojo-typings/src/main/typings/dijit/layout.d.ts b/dojo-typings/src/main/typings/dijit/layout.d.ts --- a/dojo-typings/src/main/typings/dijit/layout.d.ts +++ b/dojo-typings/src/main/typings/dijit/layout.d.ts @@ -204,7 +204,7 @@ declare namespace dijit { * Note that the initialization parameter / argument to set("content", ... * can be a String, DomNode, Nodelist, or _Widget. */ - content: dojo.ContentSetterContent | dijit._Widget; + content: any; /** * Extract visible content from inside of `<body> .... </body>` diff --git a/dojo-typings/src/main/typings/dijit/modules.d.ts b/dojo-typings/src/main/typings/dijit/modules.d.ts --- a/dojo-typings/src/main/typings/dijit/modules.d.ts +++ b/dojo-typings/src/main/typings/dijit/modules.d.ts @@ -283,7 +283,7 @@ declare module 'dijit/form/ComboBox' { } declare module 'dijit/form/ComboBoxMixin' { - type ComboBoxMixin<T, U extends dojo.store.api.BaseQueryType, V> = dijit.form.ComboBoxMixin<T, U, V>; + type ComboBoxMixin<T = any, U extends dojo.store.api.BaseQueryType = dojo.store.api.BaseQueryType, V = any> = dijit.form.ComboBoxMixin<T, U, V>; const ComboBoxMixin: dijit.form.ComboBoxConstructor; export = ComboBoxMixin; } @@ -343,7 +343,7 @@ declare module 'dijit/form/HorizontalSli } declare module 'dijit/form/MappedTextBox' { - type MappedTextBox<C extends dijit.form.Constraints> = dijit.form.MappedTextBox<C>; + type MappedTextBox<C extends dijit.form.Constraints = dijit.form.Constraints> = dijit.form.MappedTextBox<C>; const MappedTextBox: dijit.form.MappedTextBoxConstructor; export = MappedTextBox; } @@ -373,7 +373,7 @@ declare module 'dijit/form/RangeBoundTex } declare module 'dijit/form/Select' { - type Select<T, Q extends dojo.store.api.BaseQueryType, O, U extends dijit._WidgetBase> = dijit.form.Select<T, Q, O, U>; + type Select<T, Q extends dojo.store.api.BaseQueryType = dojo.store.api.BaseQueryType, O = any, U extends dijit._WidgetBase = dijit._WidgetBase> = dijit.form.Select<T, Q, O, U>; const Select: dijit.form.SelectConstructor; export = Select; } @@ -403,7 +403,7 @@ declare module 'dijit/form/ToggleButton' } declare module 'dijit/form/ValidationTextBox' { - type ValidationTextBox<C extends dijit.form.Constraints> = dijit.form.ValidationTextBox<C>; + type ValidationTextBox<C extends dijit.form.Constraints = dijit.form.Constraints> = dijit.form.ValidationTextBox<C>; const ValidationTextBox: dijit.form.ValidationTextBoxConstructor; export = ValidationTextBox; } 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 @@ -14,14 +14,32 @@ interface ScheduleWidgetEvents { }; } -declare class ScheduleWidget extends _WidgetBase<ScheduleWidgetAttrs, ScheduleWidgetEvents> { +class ScheduleWidget extends _WidgetBase<ScheduleWidgetAttrs, ScheduleWidgetEvents> { data: string[]; + + _onClick() { + this.set("data", "", ""); + + const t = this.get("title"); + this.set({ + data: ["",""] + }); + } + + render(){ + watch(this, "title", v => String(v) ); + } } const w = new ScheduleWidget({title: "Year schedule", data: ["a", "b"] }); w.get("data"); +w.set("data", "a","b"); +w.set({ + data: ["a", "b"] +}); + w.watch((p, o, n) => [p,o,n]); w.watch("data", (p, o, n) => [p,o,n]);