Skip to content

Commit 40a7aee

Browse files
authored
feat(types): better readability, intellisense improvements, small fixes
This PR adds small improvements as well as a few quickfixes to the first types iteration: Some properties and behaviors where missing for calendar, api, modal, search and toast. The DefititelyTyped link has been removed from index.d.ts. I've also rewritten modules definitions to be more readable, extensible, and to get rid of this awful _Impl interface system (new versions of Typescript are way more flexible for that). As the cherry on the top, Intellisense seems to better undertstand definitions and autocompletion works better than before 🎉
1 parent 569cce1 commit 40a7aee

25 files changed

+6640
-8243
lines changed

types/fomantic-ui-accordion.d.ts

Lines changed: 166 additions & 172 deletions
Original file line numberDiff line numberDiff line change
@@ -28,172 +28,168 @@ declare namespace FomanticUI {
2828
(behavior: 'toggle', index: number): JQuery;
2929

3030
(behavior: 'destroy'): JQuery;
31-
<K extends keyof AccordionSettings>(
32-
behavior: 'setting',
33-
name: K,
34-
value?: undefined,
35-
): AccordionSettings._Impl[K];
36-
<K extends keyof AccordionSettings>(behavior: 'setting', name: K, value: AccordionSettings._Impl[K]): JQuery;
37-
(behavior: 'setting', value: AccordionSettings): JQuery;
38-
(settings?: AccordionSettings): JQuery;
31+
<K extends keyof AccordionSettings>(behavior: 'setting', name: K, value?: undefined, ): Partial<Pick<AccordionSettings, keyof AccordionSettings>>;
32+
<K extends keyof AccordionSettings>(behavior: 'setting', name: K, value: AccordionSettings[K]): JQuery;
33+
(behavior: 'setting', value: Partial<Pick<AccordionSettings, keyof AccordionSettings>>): JQuery;
34+
(settings?: Partial<Pick<AccordionSettings, keyof AccordionSettings>>): JQuery;
3935
}
4036

4137
/**
4238
* @see {@link https://fomantic-ui.com/modules/accordion.html#/settings}
4339
*/
44-
type AccordionSettings = AccordionSettings.Param;
45-
46-
namespace AccordionSettings {
47-
type Param = Pick<_Impl, 'exclusive'> & Partial<Pick<_Impl, keyof _Impl>>;
48-
49-
interface _Impl {
50-
// region Accordion Settings
51-
52-
/**
53-
* Only allow one section open at a time.
54-
* @default true
55-
*/
56-
exclusive: boolean;
57-
58-
/**
59-
* Event on 'title' that will cause accordion to open.
60-
* @default 'click'
61-
*/
62-
on: string;
63-
64-
/**
65-
* Whether child content opacity should be animated (may cause performance issues with many child elements).
66-
* @default true
67-
*/
68-
animateChildren: boolean;
69-
70-
/**
71-
* Close open nested accordion content when an element closes.
72-
* @default true
73-
*/
74-
closeNested: boolean;
75-
76-
/**
77-
* Allow active sections to collapse.
78-
* @default true
79-
*/
80-
collapsible: boolean;
81-
82-
/**
83-
* Duration in ms of opening animation.
84-
* @default 500
85-
*/
86-
duration: number;
87-
88-
/**
89-
* Easing of opening animation. EaseInOutQuint is included with accordion, for additional options you must include easing equations.
90-
* @see {@link http://gsgd.co.uk/sandbox/jquery/easing/}
91-
* @default 'easeInOutQuint'
92-
*/
93-
easing: string;
94-
95-
// endregion
96-
97-
// region Callbacks
98-
99-
/**
100-
* Callback before element opens.
101-
*/
102-
onOpening(this: JQuery): void;
103-
104-
/**
105-
* Callback after element is open.
106-
*/
107-
onOpen(this: JQuery): void;
108-
109-
/**
110-
* Callback before element closes.
111-
*/
112-
onClosing(this: JQuery): void;
113-
114-
/**
115-
* Callback after element is closed.
116-
*/
117-
onClose(this: JQuery): void;
118-
119-
/**
120-
* Callback before element opens or closes.
121-
*/
122-
onChanging(this: JQuery): void;
123-
124-
/**
125-
* Callback before element opens or closes.
126-
*/
127-
onChange(this: JQuery): void;
128-
129-
// endregion
130-
131-
// region DOM Settings
132-
133-
/**
134-
* DOM Selectors used internally.
135-
* Selectors used to find parts of a module.
136-
*/
137-
selector: Accordion.SelectorSettings;
138-
139-
/**
140-
* Class names used to determine element state.
141-
*/
142-
className: Accordion.ClassNameSettings;
143-
144-
// endregion
145-
146-
// region Debug Settings
147-
148-
/**
149-
* Name used in log statements
150-
*/
151-
name: string;
152-
153-
/**
154-
* Event namespace. Makes sure module teardown does not effect other events attached to an element.
155-
*/
156-
namespace: string;
157-
158-
/**
159-
* Silences all console output including error messages, regardless of other debug settings.
160-
*/
161-
silent: boolean;
162-
163-
/**
164-
* Debug output to console
165-
*/
166-
debug: boolean;
167-
168-
/**
169-
* Show console.table output with performance metrics
170-
*/
171-
performance: boolean;
172-
173-
/**
174-
* Debug output includes all internal behaviors
175-
*/
176-
verbose: boolean;
177-
178-
error: Accordion.ErrorSettings;
179-
180-
// endregion
181-
}
40+
interface AccordionSettings {
41+
// region Accordion Settings
42+
43+
/**
44+
* Only allow one section open at a time.
45+
* @default true
46+
*/
47+
exclusive?: boolean | undefined;
48+
49+
/**
50+
* Event on 'title' that will cause accordion to open.
51+
* @default 'click'
52+
*/
53+
on: string;
54+
55+
/**
56+
* Whether child content opacity should be animated (may cause performance issues with many child elements).
57+
* @default true
58+
*/
59+
animateChildren: boolean;
60+
61+
/**
62+
* Close open nested accordion content when an element closes.
63+
* @default false
64+
*/
65+
closeNested: boolean;
66+
67+
/**
68+
* Allow active sections to collapse.
69+
* @default true
70+
*/
71+
collapsible: boolean;
72+
73+
/**
74+
* Duration in ms of opening animation.
75+
* @default 350
76+
*/
77+
duration: number;
78+
79+
/**
80+
* Easing of opening animation. EaseInOutQuint is included with accordion, for additional options you must include easing equations.
81+
* @see {@link http://gsgd.co.uk/sandbox/jquery/easing/}
82+
* @default 'easeOutQuad'
83+
*/
84+
easing: string;
85+
86+
/**
87+
* Whether accordion should automatically refresh on DOM insertion
88+
* @default true
89+
*/
90+
observeChanges: boolean;
91+
92+
// endregion
93+
94+
// region Callbacks
95+
96+
/**
97+
* Callback before element opens.
98+
*/
99+
onOpening(this: JQuery): void;
100+
101+
/**
102+
* Callback after element is open.
103+
*/
104+
onOpen(this: JQuery): void;
105+
106+
/**
107+
* Callback before element closes.
108+
*/
109+
onClosing(this: JQuery): void;
110+
111+
/**
112+
* Callback after element is closed.
113+
*/
114+
onClose(this: JQuery): void;
115+
116+
/**
117+
* Callback before element opens or closes.
118+
*/
119+
onChanging(this: JQuery): void;
120+
121+
/**
122+
* Callback before element opens or closes.
123+
*/
124+
onChange(this: JQuery): void;
125+
126+
// endregion
127+
128+
// region DOM Settings
129+
130+
/**
131+
* DOM Selectors used internally.
132+
* Selectors used to find parts of a module.
133+
*/
134+
selector: Accordion.SelectorSettings;
135+
136+
/**
137+
* Class names used to determine element state.
138+
*/
139+
className: Accordion.ClassNameSettings;
140+
141+
// endregion
142+
143+
// region Debug Settings
144+
145+
/**
146+
* Name used in log statements
147+
* @default 'Accordion'
148+
*/
149+
name: string;
150+
151+
/**
152+
* Event namespace. Makes sure module teardown does not effect other events attached to an element.
153+
* @default 'accordion'
154+
*/
155+
namespace: string;
156+
157+
/**
158+
* Silences all console output including error messages, regardless of other debug settings.
159+
* @default false
160+
*/
161+
silent: boolean;
162+
163+
/**
164+
* Debug output to console
165+
* @default false
166+
*/
167+
debug: boolean;
168+
169+
/**
170+
* Show console.table output with performance metrics
171+
* @default true
172+
*/
173+
performance: boolean;
174+
175+
/**
176+
* Debug output includes all internal behaviors
177+
* @default false
178+
*/
179+
verbose: boolean;
180+
181+
error: Accordion.ErrorSettings;
182+
183+
// endregion
182184
}
183185

184186
namespace Accordion {
185-
type SelectorSettings = SelectorSettings.Param;
186-
187-
namespace SelectorSettings {
188-
type Param = (
189-
| Pick<_Impl, 'accordion'>
190-
| Pick<_Impl, 'title'>
191-
| Pick<_Impl, 'trigger'>
192-
| Pick<_Impl, 'content'>
193-
) &
194-
Partial<Pick<_Impl, keyof _Impl>>;
195-
196-
interface _Impl {
187+
type SelectorSettings = Partial<Pick<Settings.Selectors, keyof Settings.Selectors>>;
188+
type ClassNameSettings = Partial<Pick<Settings.ClassNames, keyof Settings.ClassNames>>;
189+
type ErrorSettings = Partial<Pick<Settings.Errors, keyof Settings.Errors>>;
190+
191+
namespace Settings {
192+
interface Selectors {
197193
/**
198194
* @default '.accordion'
199195
*/
@@ -209,19 +205,18 @@ declare namespace FomanticUI {
209205
*/
210206
trigger: string;
211207

208+
/**
209+
* @default '.ui.dropdown'
210+
*/
211+
ignore: string;
212+
212213
/**
213214
* @default '.content'
214215
*/
215216
content: string;
216217
}
217-
}
218218

219-
type ClassNameSettings = ClassNameSettings.Param;
220-
221-
namespace ClassNameSettings {
222-
type Param = (Pick<_Impl, 'active'> | Pick<_Impl, 'animating'>) & Partial<Pick<_Impl, keyof _Impl>>;
223-
224-
interface _Impl {
219+
interface ClassNames {
225220
/**
226221
* @default 'active'
227222
*/
@@ -231,15 +226,14 @@ declare namespace FomanticUI {
231226
* @default 'animating'
232227
*/
233228
animating: string;
234-
}
235-
}
236-
237-
type ErrorSettings = ErrorSettings.Param;
238229

239-
namespace ErrorSettings {
240-
type Param = Pick<_Impl, 'method'> & Partial<Pick<_Impl, keyof _Impl>>;
230+
/**
231+
* @default 'transition'
232+
*/
233+
transition: string;
234+
}
241235

242-
interface _Impl {
236+
interface Errors {
243237
/**
244238
* @default 'The method you called is not defined.'
245239
*/

0 commit comments

Comments
 (0)