Merge pull request #27 from IT4Change/typechecks

feat(frontend): typechecks & type cleanups
This commit is contained in:
Ulf Gebhardt 2023-12-14 00:23:07 +01:00 committed by GitHub
commit eeaaa1f5e7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 715 additions and 151 deletions

836
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -129,7 +129,9 @@
"stylelint-config-recommended-vue": "^1.5.0", "stylelint-config-recommended-vue": "^1.5.0",
"stylelint-config-standard": "^34.0.0", "stylelint-config-standard": "^34.0.0",
"stylelint-config-standard-scss": "^11.1.0", "stylelint-config-standard-scss": "^11.1.0",
"vite-plugin-checker": "^0.6.2",
"vitest": "^0.34.6", "vitest": "^0.34.6",
"vue-tsc": "^1.8.25",
"vuepress": "^2.0.0-rc.0" "vuepress": "^2.0.0-rc.0"
}, },
"imports": { "imports": {

View File

@ -1,5 +1,5 @@
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate' import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import { createSSRApp, defineComponent, h, markRaw, reactive } from 'vue' import { createSSRApp, defineComponent, h, markRaw, reactive, Component } from 'vue'
import PageShell from '#components/PageShell.vue' import PageShell from '#components/PageShell.vue'
import { setPageContext } from '#context/usePageContext' import { setPageContext } from '#context/usePageContext'
@ -7,13 +7,13 @@ import i18n from '#plugins/i18n'
import pinia from '#plugins/pinia' import pinia from '#plugins/pinia'
import CreateVuetify from '#plugins/vuetify' import CreateVuetify from '#plugins/vuetify'
import type { Component } from '#types/Component'
import type { PageContext, VikePageContext } from '#types/PageContext' import type { PageContext, VikePageContext } from '#types/PageContext'
const vuetify = CreateVuetify(i18n) const vuetify = CreateVuetify(i18n)
function createApp(pageContext: VikePageContext & PageContext, isClient = true) { function createApp(pageContext: VikePageContext & PageContext, isClient = true) {
let rootComponent: Component // eslint-disable-next-line no-use-before-define
let rootComponent: InstanceType<typeof PageWithWrapper>
const PageWithWrapper = defineComponent({ const PageWithWrapper = defineComponent({
data: () => ({ data: () => ({
Page: markRaw(pageContext.Page), Page: markRaw(pageContext.Page),
@ -26,7 +26,7 @@ function createApp(pageContext: VikePageContext & PageContext, isClient = true)
}, },
render() { render() {
return h( return h(
PageShell, PageShell as Component,
{}, {},
{ {
default: () => { default: () => {
@ -49,9 +49,7 @@ function createApp(pageContext: VikePageContext & PageContext, isClient = true)
objectAssign(app, { objectAssign(app, {
changePage: (pageContext: VikePageContext & PageContext) => { changePage: (pageContext: VikePageContext & PageContext) => {
Object.assign(pageContextReactive, pageContext) Object.assign(pageContextReactive, pageContext)
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
rootComponent.Page = markRaw(pageContext.Page) rootComponent.Page = markRaw(pageContext.Page)
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
rootComponent.pageProps = markRaw(pageContext.pageProps || {}) rootComponent.pageProps = markRaw(pageContext.pageProps || {})
}, },
}) })

View File

@ -5,6 +5,7 @@ import type { Meta, StoryObj } from '@storybook/vue3'
// More on how to set up stories at: https://storybook.js.org/docs/vue/writing-stories/introduction // More on how to set up stories at: https://storybook.js.org/docs/vue/writing-stories/introduction
const meta = { const meta = {
title: 'Example/Button', title: 'Example/Button',
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
component: ExampleButton, component: ExampleButton,
// This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/vue/writing-docs/autodocs // This component will have an automatically generated docsPage entry: https://storybook.js.org/docs/vue/writing-docs/autodocs
tags: ['autodocs'], tags: ['autodocs'],

View File

@ -8,9 +8,11 @@ const meta = {
* to learn how to generate automatic titles * to learn how to generate automatic titles
*/ */
title: 'Example/Header', title: 'Example/Header',
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
component: ExampleHeader, component: ExampleHeader,
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
render: (args: any) => ({ render: (args: any) => ({
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
components: { ExampleHeader }, components: { ExampleHeader },
setup() { setup() {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment

View File

@ -6,8 +6,10 @@ import type { Meta, StoryObj } from '@storybook/vue3'
const meta = { const meta = {
title: 'Example/Page', title: 'Example/Page',
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
component: ExamplePage, component: ExamplePage,
render: () => ({ render: () => ({
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
components: { ExamplePage }, components: { ExamplePage },
template: '<example-page />', template: '<example-page />',
}), }),

View File

@ -1,2 +0,0 @@
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type Component = any

6
types/vue.d.ts vendored
View File

@ -1,5 +1 @@
declare module '*.vue' { declare module '*.vue'
import Vue from 'vue'
export default Vue
}

View File

@ -4,6 +4,7 @@ import vueI18n from '@intlify/unplugin-vue-i18n/vite'
import vue from '@vitejs/plugin-vue' import vue from '@vitejs/plugin-vue'
import vike from 'vike/plugin' import vike from 'vike/plugin'
import { UserConfig } from 'vite' import { UserConfig } from 'vite'
import { checker } from 'vite-plugin-checker'
const isStorybook = () => const isStorybook = () =>
['storybook', 'storybook:build'].includes(process.env.npm_lifecycle_event as string) ['storybook', 'storybook:build'].includes(process.env.npm_lifecycle_event as string)
@ -16,6 +17,10 @@ const config: UserConfig = {
ssr: true, ssr: true,
include: path.resolve(__dirname, './src/locales/**'), include: path.resolve(__dirname, './src/locales/**'),
}), }),
checker({
typescript: true,
vueTsc: true,
}),
], ],
build: { build: {
outDir: './build', outDir: './build',