Skip to content

Commit 4d170b1

Browse files
committed
Use AuthTokenSection in App (build fails with TS errors)
* package.json: add Nextcloud, Vue, typescipt dependencies (from Nextcloud) * remove .ts suffix from import paths (causes build error otherwise) * add declare global to define Nextcloud types. This should be changed to @nextcloud/typings. * annotated import of Nextcloud components (JS) with @ts-expect-error to solve tsc errors. This is most likely due to missing type definitions. Unclear how Nextcloud core made this working. * tsconfig: extend from @vue/tsconfig/tsconfig.json as documented elsewhere and as done in Nextcloud's core tsconfig.json * the eslint rule set @nextcloud/eslint-config/typescript was added to prevent: ERROR in [eslint] /app/src/components/AuthTokenSection.vue 35:27 error "@nextcloud/initial-state" is not published n/no-unpublished-import 36:32 error "@nextcloud/l10n" is not published n/no-unpublished-import I can only assume that that rule is disabled in the rule set we extend from or that the module resolution "node" can not find the files. The error actually complains about the module not being part of "dependencies" in package.json, which is the case, however. The internet calls for allowing such modules, which IMO defeats the purpose. The rule is also present in Nextcloud's core config. Build fails with errors like ERROR in /app/src/components/AuthTokenSetup.vue.ts 47:9-14 [tsl] ERROR in /app/src/components/AuthTokenSetup.vue.ts(47,10) TS2339: Property 'reset' does not exist on type 'CreateComponentPublicInstance<{}, { authTokenStore: Store<"auth-token", { tokens: IToken[]; }, {}, { updateToken(token: IToken): Promise<any>; addToken(name: string): Promise<ITokenResponse | null>; deleteToken(token: IToken): Promise<...>; wipeToken(token: IToken): Promise<...>; renameToken(token: IToken, newName: ...'. This hints at Typescript not being able to infer types from the component definition. Related issues: * vuejs/vue#9873 * vuejs/vue#12628 * vuejs/vue#8721 Unsuccessfully attempted proposed solutions: * Declaring return types on methods like: reset(): void { async submit(): Promise<void> { * Using arrow functions Did not work and would introduce new errors anyway * Defining interfaces for the returned component Caused another rabbit hole of more and more required type definitions, that should be infered by the Vue typings anyway
1 parent a316007 commit 4d170b1

File tree

7 files changed

+66
-14
lines changed

7 files changed

+66
-14
lines changed

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module.exports = {
22
extends: [
33
'@nextcloud',
4+
'@nextcloud/eslint-config/typescript',
45
],
56
rules: {
67
'jsdoc/require-jsdoc': 'off',

src/App.vue

+24-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,35 @@
1+
<!--
2+
SPDX-FileLicenseText: 2024 Thomas Lehmann <t.lehmann@strato.de>
3+
SPDX-License-Identifier: AGPL-3.0-or-later
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as
7+
published by the Free Software Foundation, either version 3 of the
8+
License, or (at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
-->
18+
119
<template>
2-
<NcAppContent>
3-
<div id="simplesettings">
4-
<h1>Hello world!</h1>
5-
</div>
6-
</NcAppContent>
20+
<AuthTokenSection />
721
</template>
822

923
<script lang="ts">
10-
import NcAppContent from '@nextcloud/vue/dist/Components/NcAppContent.js'
24+
import AuthTokenSection from './components/AuthTokenSection.vue'
25+
import { defineComponent } from 'vue'
1126

12-
export default {
27+
export default defineComponent({
1328
name: 'App',
1429
components: {
15-
NcAppContent,
30+
AuthTokenSection,
1631
},
17-
}
32+
})
1833
</script>
1934

2035
<style scoped lang="scss">

src/components/AuthToken.vue

+26-1
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,41 @@ import type { IToken } from '../store/authtoken'
100100
import { mdiCheck, mdiCellphone, mdiTablet, mdiMonitor, mdiWeb, mdiKey, mdiMicrosoftEdge, mdiFirefox, mdiGoogleChrome, mdiAppleSafari, mdiAndroid, mdiAppleIos } from '@mdi/js'
101101
import { translate as t } from '@nextcloud/l10n'
102102
import { defineComponent } from 'vue'
103-
import { TokenType, useAuthTokenStore } from '../store/authtoken.ts'
103+
import { TokenType, useAuthTokenStore } from '../store/authtoken'
104104

105+
// @ts-expect-error: Cannot find module or its corresponding type declarations.
105106
import NcActions from '@nextcloud/vue/dist/Components/NcActions.js'
107+
// @ts-expect-error: Cannot find module or its corresponding type declarations.
106108
import NcActionButton from '@nextcloud/vue/dist/Components/NcActionButton.js'
109+
// @ts-expect-error: Cannot find module or its corresponding type declarations.
107110
import NcActionCheckbox from '@nextcloud/vue/dist/Components/NcActionCheckbox.js'
111+
// @ts-expect-error: Cannot find module or its corresponding type declarations.
108112
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
113+
// @ts-expect-error: Cannot find module or its corresponding type declarations.
109114
import NcDateTime from '@nextcloud/vue/dist/Components/NcDateTime.js'
115+
// @ts-expect-error: Cannot find module or its corresponding type declarations.
110116
import NcIconSvgWrapper from '@nextcloud/vue/dist/Components/NcIconSvgWrapper.js'
117+
// @ts-expect-error: Cannot find module or its corresponding type declarations.
111118
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
112119

120+
declare global {
121+
interface Window {
122+
oc_defaults: {
123+
baseUrl: string;
124+
docBaseUrl: string;
125+
docPlaceholderUrl: string;
126+
entity: string;
127+
folder: string;
128+
logoClaim: string;
129+
name: string;
130+
productName: string;
131+
slogan: string;
132+
syncClientUrl: string;
133+
title: string;
134+
};
135+
}
136+
}
137+
113138
// When using capture groups the following parts are extracted the first is used as the version number, the second as the OS
114139
const userAgentMap = {
115140
ie: /(?:MSIE|Trident|Trident\/7.0; rv)[ :](\d+)/,

src/components/AuthTokenSetup.vue

+2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ import { translate as t } from '@nextcloud/l10n'
4848
import { defineComponent } from 'vue'
4949
import { useAuthTokenStore, type ITokenResponse } from '../store/authtoken'
5050

51+
// @ts-expect-error: Cannot find module or its corresponding type declarations.
5152
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
53+
// @ts-expect-error: Cannot find module or its corresponding type declarations.
5254
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
5355

5456
import AuthTokenSetupDialog from './AuthTokenSetupDialog.vue'

src/components/AuthTokenSetupDialog.vue

+4
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,13 @@ import { getRootUrl } from '@nextcloud/router'
7070
import { defineComponent, type PropType } from 'vue'
7171

7272
import QR from '@chenfengyuan/vue-qrcode'
73+
// @ts-expect-error: Cannot find module or its corresponding type declarations.
7374
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
75+
// @ts-expect-error: Cannot find module or its corresponding type declarations.
7476
import NcDialog from '@nextcloud/vue/dist/Components/NcDialog.js'
77+
// @ts-expect-error: Cannot find module or its corresponding type declarations.
7578
import NcIconSvgWrapper from '@nextcloud/vue/dist/Components/NcIconSvgWrapper.js'
79+
// @ts-expect-error: Cannot find module or its corresponding type declarations.
7680
import NcTextField from '@nextcloud/vue/dist/Components/NcTextField.js'
7781

7882
import logger from '../logger'

src/store/authtoken.ts

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ import { defineStore } from 'pinia'
2929
import axios from '@nextcloud/axios'
3030
import logger from '../logger'
3131

32+
declare global {
33+
// TODO find matching typedef in the @nextcloud/dialogs package
34+
interface Window { OC: any; }
35+
}
36+
3237
const BASE_URL = generateUrl('/simplesettings/authtokens')
3338

3439
const confirm = () => {

tsconfig.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// Mostly based on Nextcloud's tsconfig.json with some modifications
33
// (includes, allowImportingTsExtensions, noEmit)
44
"extends": "@vue/tsconfig/tsconfig.json",
5-
"include": ["./src/**/*.ts", "./src/**/*.vue"],
5+
"include": ["./src/**/*.ts", "./src/**/*.vue", "./src/**/*.d.ts"],
66
"compilerOptions": {
77
"types": ["node", "vue", "vue-router"],
88
"outDir": "./dist/",
99
"target": "ESNext",
1010
"module": "esnext",
11-
// Set module resolution to bundler and `noEmit` to be able to set `allowImportingTsExtensions`, so we can import Typescript with .ts extension
12-
"moduleResolution": "Bundler",
13-
"allowImportingTsExtensions": true,
11+
"moduleResolution": "node",
12+
// Must be false because noEmit is false (reason see below)
13+
"allowImportingTsExtensions": false,
1414
// noEmit shall be false to prevent the error
1515
// "Error: TypeScript emitted no output for /app/src/main.ts."
1616
"noEmit": false,

0 commit comments

Comments
 (0)