Skip to content

Commit e29fad1

Browse files
docs: Add types for components (#2273)
1 parent 50d223a commit e29fad1

8 files changed

Lines changed: 39 additions & 12 deletions

File tree

docs/.vitepress/components/BlogHome.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { computed } from 'vue';
33
// @ts-expect-error: Vitepress data-loader magic, this import is correct
44
import { data } from '../loaders/blog.data';
55
import BlogPostPreview from './BlogPostPreview.vue';
6+
import { Post } from '../utils/types';
67
7-
const posts = computed(() =>
8+
const posts = computed<Post[]>(() =>
89
data
910
.map((post) => ({
1011
...post,

docs/.vitepress/components/BlogLayout.vue

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
<script lang="ts" setup>
22
import useBlogDate from '../composables/useBlogDate';
3-
import { useData } from 'vitepress';
3+
import { Content, useData } from 'vitepress';
4+
import { PostFrontmatter } from '../utils/types';
45
5-
const { frontmatter } = useData();
6+
const { frontmatter } = useData<PostFrontmatter>();
67
const date = useBlogDate(() => frontmatter.value.date);
78
</script>
89

910
<template>
1011
<div class="vp-doc">
1112
<main class="container-content">
12-
<h1 v-html="$frontmatter.title" />
13+
<h1 v-html="frontmatter.title" />
1314
<p class="meta-row">
1415
<a
15-
class="author"
16-
v-for="author of $frontmatter.authors"
16+
v-for="author of frontmatter.authors"
1717
:key="author.github"
1818
:href="`https://github.com/${author.github}`"
19+
class="author"
1920
>
2021
<img :src="`https://github.com/${author.github}.png?size=96`" />
2122
<span>{{ author.name }}</span>

docs/.vitepress/components/ExampleSearch.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts" setup>
2-
import { ref, onMounted, computed, toRaw, Ref } from 'vue';
2+
import { computed, onMounted, ref, Ref, toRaw } from 'vue';
33
import ExampleSearchFilterByItem from './ExampleSearchFilterByItem.vue';
44
import ExampleSearchResult from './ExampleSearchResult.vue';
55
import { ExamplesMetadata, KeySelectedObject } from '../utils/types';
@@ -48,7 +48,7 @@ function doesExampleMatchSelected(
4848
4949
const filteredExamples = computed(() => {
5050
const text = searchText.value.toLowerCase();
51-
return exampleMetadata.value.examples.filter((example) => {
51+
return exampleMetadata.value?.examples.filter((example) => {
5252
const matchesText = example.searchText.toLowerCase().includes(text);
5353
const matchesApis = doesExampleMatchSelected(example.apis, requiredApis);
5454
const matchesPermissions = doesExampleMatchSelected(

docs/.vitepress/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Feed } from 'feed';
2+
// @ts-expect-error; It isn't TypeScript lib
23
import footnote from 'markdown-it-footnote';
34
import fs, { readFile } from 'node:fs/promises';
45
import { join } from 'node:path';
@@ -73,8 +74,11 @@ export default defineConfig({
7374
description,
7475
vite: {
7576
clearScreen: false,
77+
//TODO: REMOVE THIS @TS-EXPECT-ERROR AFTER BUMP VITEPRESS TO V2.0
7678
plugins: [
79+
// @ts-expect-error: Vite version mismatch between this project and the plugin
7780
llmstxt(),
81+
// @ts-expect-error: Vite version mismatch between this project and the plugin
7882
groupIconVitePlugin({
7983
customIcon: {
8084
'wxt.config.ts': localIconLoader(
Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1-
import { createContentLoader } from 'vitepress';
1+
import { type ContentData, createContentLoader } from 'vitepress';
2+
import { PostFrontmatter } from '../utils/types';
23

3-
export default createContentLoader('blog/*.md');
4+
declare const data: Array<ContentData & { frontmatter: PostFrontmatter }>;
5+
export { data };
6+
7+
export default createContentLoader<
8+
Array<ContentData & { frontmatter: PostFrontmatter }>
9+
>('blog/*.md');

docs/.vitepress/theme/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import ExampleSearch from '../components/ExampleSearch.vue';
66
import BlogLayout from '../components/BlogLayout.vue';
77
import './custom.css';
88
import 'virtual:group-icons.css';
9+
import type { EnhanceAppContext } from 'vitepress/client';
910

1011
export default {
1112
extends: DefaultTheme,
12-
enhanceApp(ctx) {
13+
enhanceApp(ctx: EnhanceAppContext) {
1314
ctx.app
1415
.component('Icon', Icon)
1516
.component('EntrypointPatterns', EntrypointPatterns)

docs/.vitepress/utils/head.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HeadConfig } from 'vitepress/types/shared';
1+
import type { HeadConfig } from 'vitepress';
22

33
export function meta(
44
property: string,

docs/.vitepress/utils/types.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { ContentData } from 'vitepress';
2+
13
export interface Example {
24
name: string;
35
description?: string;
@@ -16,3 +18,15 @@ export type ExamplesMetadata = {
1618
};
1719

1820
export type KeySelectedObject = Record<string, boolean | undefined>;
21+
22+
export interface PostFrontmatter {
23+
title: string;
24+
description?: string;
25+
date: Date;
26+
authors: { name: string; github: string }[];
27+
}
28+
29+
export interface Post
30+
extends Omit<ContentData, 'frontmatter'>, Omit<PostFrontmatter, 'date'> {
31+
date: Date;
32+
}

0 commit comments

Comments
 (0)