# Type Checking

Type-check your config and pages.

`vue-tsc` checks Markdown pages like `.vue` files. It reports errors like an unknown prop, a wrong value type or an undefined name at their line in the page:

```md title="content/index.md" lineNumbers
---
title: Introduction
---

<Callout tpye="warn"> <!-- [!code word:tpye] -->
This can't be undone.
</Callout>
```

```txt
content/index.md(5,10): error TS2353: Object literal may only specify known properties,
and 'tpye' does not exist in type '{ readonly title?: string | undefined; ... }'.
```

A site created by `create-vuesho` already has the setup below. Run the check with `npm run types:check`.

## Setup [#setup]

### Install the Packages [#install-the-packages-step]

`vue-tsc` needs TypeScript 6's JavaScript API, which TypeScript 7 doesn't have:

```npm
npm i -D typescript@6 vue-tsc @types/node
```

### Add a `tsconfig.json` [#add-a-tsconfigjson-step]

Vuesho's types need `ES2023` or later, and the Node.js and Vite types:

```jsonc title="tsconfig.json"
{
  "compilerOptions": {
    "target": "ES2023",
    "lib": ["ES2023", "DOM", "DOM.Iterable"],
    "module": "ESNext",
    "moduleResolution": "Bundler",
    "strict": true,
    "noEmit": true,
    "skipLibCheck": true,
    // Checks JavaScript files, and `<script setup>` without `lang="ts"`.
    "allowJs": true,
    "checkJs": true,
    "types": ["node", "vite/client"],
  },
  "include": ["*.ts", "src", "content"],
  "vueCompilerOptions": {
    // Reads `.md` files as Vue. VitePress isn't needed.
    "vitePressExtensions": [".md"],
    // Reads a page as Vuesho compiles it.
    "plugins": ["vuesho/type-check"],
    // Reports a prop that a component doesn't declare.
    "checkUnknownProps": true,
    // Reports a component that the page can't resolve.
    "checkUnknownComponents": true,
    // Allows `data-*` attributes on every component.
    "dataAttributes": ["data-*"],
  },
}
```

### Run the Check [#run-the-check-step]

```json title="package.json"
{
  "scripts": {
    "postinstall": "vuesho prepare",
    "types:check": "vuesho prepare && vue-tsc --noEmit"
  }
}
```

```npm
npm run types:check
```

`vuesho prepare` writes the list of the components that pages use, which the type check and the editor read. Run it again after you add a component or change `vuesho.config.ts`, unless `vuesho dev` is running. The `postinstall` script runs it after each install.

## Checked Syntax [#checked-syntax]

`vuesho/type-check` checks the components and the expressions of each page, and skips code blocks and escaped text, like `\{{ name }}`. It types the [path params](/routing#path-params) of a page and the argument of its `frontmatter` function, and the params of a [custom page](/routing#custom-pages) from its file path.

Each page gets the components of `src/components/content/`, of its collection's folder and of the plugins. A component that the page imports takes priority over one from a folder.

## Editor Support [#editor-support]

The [Vue extension](https://marketplace.visualstudio.com/items?itemName=Vue.volar) for VS Code checks pages as you write them, after you turn it on for Markdown:

```json title=".vscode/settings.json"
{
  "vue.server.includeLanguages": ["vue", "markdown"]
}
```

## Custom Syntax [#custom-syntax]

Some [markdown-it plugins](/markdown#markdown-it-plugins) add syntax that looks like Vue, like KaTeX braces. List them in the `vuesho/type-check` options:

```jsonc title="tsconfig.json"
{
  "vueCompilerOptions": {
    "plugins": [
      {
        "name": "vuesho/type-check",
        // Each entry resolves from the folder of `tsconfig.json`.
        "markdownItPlugins": [
          "@mdit/plugin-katex#katex", // A named export of a package
          "markdown-it-footnote", // The default export of a package
          "./src/syntax.js", // A file
          ["markdown-it-container", "tip"], // A plugin with its options
        ],
      },
    ],
  },
}
```

## Other Content Folders [#other-content-folders]

For a [collection](/markdown/collections) outside `content/`, add its folder to `include`:

```jsonc title="tsconfig.json"
{
  "include": ["*.ts", "src", "content", "blog"],
}
```
