Skip to content

Commit

Permalink
ts: change declare by .d.ts referencing @nextcloud/typings
Browse files Browse the repository at this point in the history
Inspired by readme of typing [1] and usage in another module [2].

Despite basing on v29 the version 28 was chosen because there's no v29
in "typings" yet.

After replacing the "any" type definition by the type reference tsc complained:

```
TS2339: Property 'confirm' does not exist on type 'Dialogs & { filepicker(title: string, callback: Function, multiselect?: boolean | undefined, mimeTypeFilter?: string[] | undefined, modal?: boolean | undefined, type?: number | undefined, path?: string | undefined, options?: FilePickerOptions | undefined): void; }'.
```

This is due to "confirm()" not being defined in @nextcloud/types.
Searching the history of typings [1] it is and never was defined.

The upgrade guide for the upcoming v30 [3] discourages using
"OC.dialogs.confirm()" and refers to @nextcloud/dialogs [4],
which does currently not provice "confirm()".

Thus a type extension was added.

[1]: https://github.com/nextcloud-libraries/nextcloud-typings
[2]: https://github.com/nextcloud-libraries/nextcloud-router/blob/v3.0.1/lib/oc.d.ts#L1
[3]: https://docs.nextcloud.com/server/latest/developer_manual/app_publishing_maintenance/app_upgrade_guide/upgrade_to_30.html#deprecated-apis
[4]: https://nextcloud-libraries.github.io/nextcloud-dialogs/
  • Loading branch information
tholewebgods committed Jun 26, 2024
1 parent c154323 commit c68ead2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
17 changes: 17 additions & 0 deletions src/oc.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// <reference types="@nextcloud/typings" />

declare namespace Nextcloud28WithPolyfills {
interface DialogsPolyfill {
confirm(
title: string,
message: string,
callback: Function,
modal: boolean): void;
}

interface OC extends Nextcloud.v28.OC {
dialogs: Nextcloud.Common.Dialogs & DialogsPolyfill;
}
}

declare var OC: Nextcloud28WithPolyfills;
5 changes: 0 additions & 5 deletions src/store/authtoken.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,6 @@ import { defineStore } from 'pinia'
import axios from '@nextcloud/axios'
import logger from '../logger'

declare global {
// TODO find matching typedef in the @nextcloud/dialogs package
interface Window { OC: any; }
}

const BASE_URL = generateUrl('/apps/simplesettings/authtokens')

const confirm = () => {
Expand Down

0 comments on commit c68ead2

Please sign in to comment.