Skip to content

Commit e77888d

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 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 0244246 commit e77888d

8 files changed

+790
-178
lines changed

package-lock.json

Lines changed: 728 additions & 166 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,30 @@
1717
"extends @nextcloud/browserslist-config"
1818
],
1919
"dependencies": {
20-
"@nextcloud/axios": "^2.0.0",
21-
"@nextcloud/dialogs": "^5.0.3",
22-
"@nextcloud/event-bus": "^3.1.0",
23-
"@nextcloud/moment": "^1.2.2",
24-
"@nextcloud/router": "^2.2.0",
25-
"@nextcloud/vue": "^8.3.0",
20+
"@chenfengyuan/vue-qrcode": "^1.0.2",
21+
"@mdi/js": "^7.4.47",
22+
"@nextcloud/dialogs": "^5.2.0",
23+
"@nextcloud/initial-state": "^2.0.0",
24+
"@nextcloud/l10n": "^2.1.0",
25+
"@nextcloud/logger": "^2.5.0",
26+
"@nextcloud/password-confirmation": "^5.0.1",
27+
"@nextcloud/router": "^3.0.0",
28+
"@nextcloud/vue": "^8.11.2",
2629
"caret-pos": "^2.0.0",
2730
"fuse.js": "^7.0.0",
2831
"linkifyjs": "^4.1.1",
2932
"lozad": "^1.16.0",
3033
"mitt": "^3.0.1",
34+
"pinia": "^2.1.7",
3135
"sass": "^1.69.5",
3236
"sass-loader": "^13.3.2",
33-
"vue": "^2.7.15",
37+
"vue": "^2.7.16",
3438
"vue-i18n": "^8.17.1",
3539
"vue-material-design-icons": "^5.2.0",
3640
"vue-modal-dialogs": "3.0.0",
3741
"vue-router": "^3.6.5",
3842
"vue-showdown": "^2.4.1",
43+
"vue-tsc": "^2.0.19",
3944
"vuejs-logger": "^1.5.5",
4045
"vuex": "^3.6.2"
4146
},
@@ -44,10 +49,12 @@
4449
"@nextcloud/browserslist-config": "^3.0.0",
4550
"@nextcloud/eslint-config": "^8.3.0",
4651
"@nextcloud/stylelint-config": "^2.3.1",
52+
"@nextcloud/typings": "^1.8.0",
4753
"@nextcloud/webpack-vue-config": "^6.0.0",
4854
"@typescript-eslint/eslint-plugin": "^6.18.0",
4955
"@typescript-eslint/parser": "^6.18.0",
5056
"@vue/cli-plugin-typescript": "~5.0.8",
57+
"@vue/tsconfig": "^0.5.1",
5158
"@vue/vue2-jest": "^29.2.6",
5259
"babel-jest": "^29.7.0",
5360
"check-peer-dependencies": "^4.3.0",

src/App.vue

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
<template>
2-
<div>dummy</div>
2+
<AuthTokenSection />
33
</template>
44

55
<script lang="ts">
6+
import AuthTokenSection from './components/AuthTokenSection.vue'
7+
import { defineComponent } from 'vue'
68
7-
export default {
9+
export default defineComponent({
810
name: 'App',
9-
}
11+
components: {
12+
AuthTokenSection,
13+
},
14+
})
1015
</script>
1116

1217
<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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
2-
"include": ["./src/**/*.ts", "./src/**/*.vue"],
2+
"extends": "@vue/tsconfig/tsconfig.json",
3+
"include": ["./src/**/*.ts", "./src/**/*.vue", "./src/**/*.d.ts"],
34
"compilerOptions": {
45
"types": ["node", "vue", "vue-router"],
56
"outDir": "./dist/",
@@ -17,5 +18,6 @@
1718
"noImplicitAny": false,
1819
"resolveJsonModule": true,
1920
"strict": true,
21+
"skipLibCheck": true,
2022
}
2123
}

0 commit comments

Comments
 (0)