question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Docs] Explain how to use TypeScript in a VitePress project

See original GitHub issue

Is your feature request related to a problem? Please describe.

Im currently migrating a VuePress 1 project over to VitePress and I would like to integrate TypeScript for my .vue files. The documentation does not explain how to enable TypeScript in a VitePress project. I’ve looked over other documentation to enable TS in a Vue 3 project but that was based on vue-cli and seems irrelevant (I could be wrong)

My IDE, VS Code, has Vue Language Features (Volar) and TypeScript Vue Plugin (Volar) installed.

Here is my eslintrc.js that was migrated over from VuePress (if relevant?)

module.exports = {
  parser: "vue-eslint-parser",
  parserOptions: {
    ecmaVersion: 2018
  },
  env: {
    node: true,
    browser: true,
    commonjs: true,
    jest: true,
    es6: true
  },
  extends: [
    "eslint:recommended",
    "plugin:vue/recommended"
  ],
  plugins: [
    "vue"
  ],
  ignorePatterns: ["dist/", "node_modules/", "*.json", ".temp/"],
  rules: {
    // Rules to ignore
    "vue/multi-word-component-names": "off",
    "no-use-before-define": "off",
    "no-case-declarations": "off",
    "no-useless-escape": "off",
    "no-control-regex": "off",
    "no-unused-vars": "off",
    "no-console": "off",
    "no-empty": "off",
    "no-prototype-builtins": "off",
    "guard-for-in": "off",
    // Rules to warn
    indent: ["warn", 2, { SwitchCase: 1 }],
    // Rules to error
    curly: "error",
    "semi-spacing": "error",
    "no-unneeded-ternary": "error",
    "no-useless-concat": "error",
    "no-useless-return": "error",
    "no-multi-spaces": "error",
    "no-alert": "error",
    "no-eq-null": "error",
    "no-eval": "error"
  }
};

Simple, when assigning a type like:

const str: string = '' nets an error: error Parsing error: Unexpected token :

Describe the solution you’d like

A section to describe what needs to be done to get TypeScript working in VitePress

Describe alternatives you’ve considered

Looked at other documentation about Vue 3, TypeScript implementation, etc. But could not find anything relating to VitePress. I’ve also looked at other projects that use VitePress and I am just not understanding what is making their files get statically type checked

Additional context

I would also like to have type checking in the file itself. For example, type checking on writing, not type checking on build or watch. I assume this has to do with VS Code extensions?

Validations

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

4reactions
Jasenkoocommented, Aug 9, 2022

To add, if anyone has a problem listing files under .vitepress, just add the .eslintignore file and add !/docs/**

4reactions
brc-ddcommented, Aug 12, 2022

Its still not complete, it’ll probably throw errors when you’ll import you vue component inside ts files (say inside .vitepress/theme/index.ts for like registering a component globally). You need some file like this:

// shims.d.ts

declare module '*.vue' {
  import type { DefineComponent } from 'vue'
  const component: DefineComponent<{}, {}, any>
  export default component
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

Working with VitePress and The New Docs Theme! - YouTube
ℹ️ About In this video, I do some live coding as we dive into VitePress and theming for the new … Show more....
Read more >
Create a document with VitePress | miyauci.me
Create a document with VitePress. Introduce the basic usage of VitePress,multilingual support, homepage layout, meta tag injection, custom CSS, custom component ...
Read more >
Creating the documentation website | Building an NPM ...
Creating the documentation website | Building an NPM Package with TypeScript. At this stage, you should have your NPM package completed. We have...
Read more >
Introduction | VitePress
docs │ ├─ .vitepress │ │ └─ config.js │ └─ index.md └─ package.json. TIP. You can also use any of .ts , .cjs...
Read more >
Johnson Chu on Twitter: "Implement VitePress support ...
TypeScript tip: Many optional properties are a code smell. Why? Because it reduces type safety. Example, I joined a project where every REST...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found