Skip to content

Commit 0f37b35

Browse files
committed
chore: add explicit types for public API
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
1 parent 1292d2e commit 0f37b35

2 files changed

Lines changed: 21 additions & 21 deletions

File tree

lib/dialogs.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export class Dialog {
3838
*
3939
* @return Promise that resolves when the dialog is answered successfully and rejects on close
4040
*/
41-
async show() {
41+
async show(): Promise<void> {
4242
const result = await spawnDialog(
4343
GenericDialog,
4444
{
@@ -89,7 +89,7 @@ export class DialogBuilder {
8989
*
9090
* @param name The name or headline of the dialog
9191
*/
92-
setName(name: string) {
92+
setName(name: string): this {
9393
this.#name = name
9494
return this
9595
}
@@ -99,7 +99,7 @@ export class DialogBuilder {
9999
*
100100
* @param text Main text of the dialog
101101
*/
102-
setText(text: string) {
102+
setText(text: string): this {
103103
this.#text = text
104104
return this
105105
}
@@ -109,7 +109,7 @@ export class DialogBuilder {
109109
*
110110
* @param severity Severity of the dialog
111111
*/
112-
setSeverity(severity: IDialogSeverity) {
112+
setSeverity(severity: IDialogSeverity): this {
113113
this.#severity = severity
114114
return this
115115
}
@@ -119,7 +119,7 @@ export class DialogBuilder {
119119
*
120120
* @param buttons Either an array of dialog buttons
121121
*/
122-
setButtons(buttons: IDialogButton[]) {
122+
setButtons(buttons: IDialogButton[]): this {
123123
if (this.#buttons.length > 0) {
124124
logger.warn('[@nextcloud/dialogs] Dialog buttons are already set - this overrides previous buttons.')
125125
}
@@ -132,12 +132,12 @@ export class DialogBuilder {
132132
*
133133
* @param button Button to add
134134
*/
135-
addButton(button: IDialogButton) {
135+
addButton(button: IDialogButton): this {
136136
this.#buttons.push(button)
137137
return this
138138
}
139139

140-
build() {
140+
build(): Dialog {
141141
return new Dialog(this.#name, this.#text, this.#buttons, this.#severity)
142142
}
143143
}
@@ -156,7 +156,7 @@ export class DialogBuilder {
156156
* .build()
157157
* ```
158158
*/
159-
export function getDialogBuilder(name: string) {
159+
export function getDialogBuilder(name: string): DialogBuilder {
160160
return new DialogBuilder(name)
161161
}
162162

lib/filepicker-builder.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ export class FilePickerBuilder<IsMultiSelect extends boolean> {
141141
*
142142
* @param container The dialog container
143143
*/
144-
public setContainer(container: string) {
144+
public setContainer(container: string): this {
145145
this.container = container
146146
return this
147147
}
@@ -161,7 +161,7 @@ export class FilePickerBuilder<IsMultiSelect extends boolean> {
161161
*
162162
* @param filter MIME type to allow
163163
*/
164-
public addMimeTypeFilter(filter: string) {
164+
public addMimeTypeFilter(filter: string): this {
165165
this.mimeTypeFilter.push(filter)
166166
return this
167167
}
@@ -171,7 +171,7 @@ export class FilePickerBuilder<IsMultiSelect extends boolean> {
171171
*
172172
* @param filter Array of allowed MIME types
173173
*/
174-
public setMimeTypeFilter(filter: string[]) {
174+
public setMimeTypeFilter(filter: string[]): this {
175175
this.mimeTypeFilter = filter
176176
return this
177177
}
@@ -182,7 +182,7 @@ export class FilePickerBuilder<IsMultiSelect extends boolean> {
182182
*
183183
* @param button The button
184184
*/
185-
public addButton(button: IFilePickerButton) {
185+
public addButton(button: IFilePickerButton): this {
186186
if (typeof this.buttons === 'function') {
187187
logger.warn('FilePicker buttons were set to factory, now overwritten with button object.')
188188
this.buttons = []
@@ -197,7 +197,7 @@ export class FilePickerBuilder<IsMultiSelect extends boolean> {
197197
*
198198
* @param factory The button factory
199199
*/
200-
public setButtonFactory(factory: IFilePickerButtonFactory) {
200+
public setButtonFactory(factory: IFilePickerButtonFactory): this {
201201
this.buttons = factory
202202
return this
203203
}
@@ -208,7 +208,7 @@ export class FilePickerBuilder<IsMultiSelect extends boolean> {
208208
* @param type The legacy filepicker type to emulate
209209
* @deprecated Use `addButton` or `setButtonFactory` instead as with setType you do not know which button was pressed
210210
*/
211-
public setType(type: FilePickerType) {
211+
public setType(type: FilePickerType): this {
212212
this.buttons = (nodes, path) => {
213213
const buttons: IFilePickerButton[] = []
214214
const node = nodes[0]
@@ -254,7 +254,7 @@ export class FilePickerBuilder<IsMultiSelect extends boolean> {
254254
*
255255
* @param allow True to allow picking directories
256256
*/
257-
public allowDirectories(allow = true) {
257+
public allowDirectories(allow = true): this {
258258
this.directoriesAllowed = allow
259259
return this
260260
}
@@ -264,7 +264,7 @@ export class FilePickerBuilder<IsMultiSelect extends boolean> {
264264
*
265265
* @param noMenu True to hide menu
266266
*/
267-
public setNoMenu(noMenu = true) {
267+
public setNoMenu(noMenu = true): this {
268268
this.noMenu = noMenu
269269
return this
270270
}
@@ -274,7 +274,7 @@ export class FilePickerBuilder<IsMultiSelect extends boolean> {
274274
*
275275
* @param path Path to start from picking
276276
*/
277-
public startAt(path: string) {
277+
public startAt(path: string): this {
278278
this.path = path
279279
return this
280280
}
@@ -284,7 +284,7 @@ export class FilePickerBuilder<IsMultiSelect extends boolean> {
284284
*
285285
* @param filter Filter function to apply
286286
*/
287-
public setFilter(filter: IFilePickerFilter) {
287+
public setFilter(filter: IFilePickerFilter): this {
288288
this.filter = filter
289289
return this
290290
}
@@ -294,23 +294,23 @@ export class FilePickerBuilder<IsMultiSelect extends boolean> {
294294
*
295295
* @param canPick Function to decide if a node can be picked
296296
*/
297-
public setCanPick(canPick: IFilePickerCanPick) {
297+
public setCanPick(canPick: IFilePickerCanPick): this {
298298
this.canPick = canPick
299299
return this
300300
}
301301

302302
/**
303303
* Disable navigation (view selection)
304304
*/
305-
public disableNavigation() {
305+
public disableNavigation(): this {
306306
this.disabledNavigation = true
307307
return this
308308
}
309309

310310
/**
311311
* Construct the configured FilePicker
312312
*/
313-
public build() {
313+
public build(): FilePicker<IsMultiSelect> {
314314
return new FilePicker<IsMultiSelect>(
315315
this.title,
316316
this.multiSelect as IsMultiSelect,

0 commit comments

Comments
 (0)