Skip to content

Commit 4ac4513

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 ca09567 commit 4ac4513

File tree

7 files changed

+48
-14
lines changed

7 files changed

+48
-14
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
<template>
2-
<NcAppContent>
3-
<div id="simplesettings">
4-
<h1>Hello world!</h1>
5-
</div>
6-
</NcAppContent>
2+
<AuthTokenSection />
73
</template>
84

95
<script lang="ts">
10-
import NcAppContent from '@nextcloud/vue/dist/Components/NcAppContent.js'
6+
import AuthTokenSection from './components/AuthTokenSection.vue'
7+
import { defineComponent } from 'vue'
118
12-
export default {
9+
export default defineComponent({
1310
name: 'App',
1411
components: {
15-
NcAppContent,
12+
AuthTokenSection,
1613
},
17-
}
14+
})
1815
</script>
1916

2017
<style scoped lang="scss">

src/components/AuthToken.vue

Lines changed: 26 additions & 1 deletion
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 5 additions & 0 deletions
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

Lines changed: 4 additions & 4 deletions
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)