From c68ead2b84711d1fb59dbd84c19b3e96bbd07513 Mon Sep 17 00:00:00 2001 From: Thomas Lehmann Date: Mon, 24 Jun 2024 17:14:05 +0200 Subject: [PATCH] ts: change declare by .d.ts referencing @nextcloud/typings 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/ --- src/oc.d.ts | 17 +++++++++++++++++ src/store/authtoken.ts | 5 ----- 2 files changed, 17 insertions(+), 5 deletions(-) create mode 100644 src/oc.d.ts diff --git a/src/oc.d.ts b/src/oc.d.ts new file mode 100644 index 0000000..27898cf --- /dev/null +++ b/src/oc.d.ts @@ -0,0 +1,17 @@ +/// + +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; diff --git a/src/store/authtoken.ts b/src/store/authtoken.ts index 3ef316b..411b1fe 100644 --- a/src/store/authtoken.ts +++ b/src/store/authtoken.ts @@ -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 = () => {