From 96e99061e9dbad6ef775897b3cfbd2a946766587 Mon Sep 17 00:00:00 2001 From: Rachel Lambda Samuelsson Date: Wed, 17 Jul 2024 16:49:08 +0200 Subject: [PATCH] better typing --- src/posts/index.ts | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/posts/index.ts b/src/posts/index.ts index f7233e5..07d9caf 100644 --- a/src/posts/index.ts +++ b/src/posts/index.ts @@ -1,4 +1,4 @@ -import type { ComponentOptions } from 'vue' +import type { Component, ComponentOptions } from 'vue' import { h, defineComponent } from 'vue' import ThePost from '../components/ThePost.vue' @@ -9,29 +9,31 @@ export type Post = { path : string, url : string, excerpt : string, - component : ComponentOptions, + component : Component, } -const imports = await Promise.all( - Object.values(import.meta.glob('./*.md')).map((m) => m()) -) +type Import = { + default : ComponentOptions & { __name : string }, + date : Date + title : string + excerpt : string +} + +const imports : Import[] = await Promise.all( + Object.values(import.meta.glob('./*.md')).map((m) => m()) +) as Import[] -// @ts-ignore const posts : Post[] = imports.map((post) => { - // @ts-ignore const slug = post.default.__name const path = "/posts/" + slug const url = path + ".html" - // @ts-ignore const date = new Date(post.date) - // @ts-ignore const title = post.title return { - // @ts-ignore excerpt: post.excerpt, title, date, slug, path, url, component: defineComponent( - (props) => { + (_) => { return () => { return h( ThePost, @@ -40,7 +42,6 @@ const posts : Post[] = imports.map((post) => { title: title }, { - // @ts-ignore default: post.default.render } )