Skip to content

AjiTae/vuedts

 
 

Repository files navigation

vuedts

This repository is fork from https://github.com/ktsn/vuetype Because that repository has not maintained now.

npm version Build Status

Generate TypeScript declaration files for .vue files

Sample Repository

kahirokunn/book-management#75

Installation

You can use vuedts command after exec one of following commands.

$ npm install --global @kahirokunn/vuedts # npm
$ yarn global add @kahirokunn/vuedts # yarn

Usage

Specify the directory that includes your .vue files as the 2nd argument of vuedts command. Note that the .vue files should have TypeScript code (in <script lang="ts"> element).

vuedts src/components

Then .vue.d.ts file corresponding .vue file will be output. So you can import each .vue component with concrete type declaration! This would help your editor inspect.

For example, if there is the following component:

<template>
  <div>{{ message }}</div>
</template>

<script lang="ts">
import Vue from 'vue'
import Component from 'vue-class-component'

@Component
export default class MyComp extends Vue {
  message = 'Hello'
}
</script>

You will acquire the following declaration file:

import Vue from 'vue';
export default class MyComp extends Vue {
    message: string;
}

Watch mode

You can enable watch mode by adding --watch (shorthand -w) flag. In the watch mode, vuedts watches update of .vue files and generates declaration files when the .vue files are updated.

vuedts --watch src/components

Output directory

You can specify output directory for typings by adding --outRoot <path>, to separate declarations and files.

#####project:

src/
    components/
        Component.vue

#####command:

vuedts --watch src/components -o generated-types

#####result:

generated-types/
    components/
        Component.d.ts
src/
    components/
        Component.vue

Use rootDirs for declarations to be recognized.

#####compilerOptions:

"rootDirs"": ["src", "generated-types"]

License

MIT

About

Generate TypeScript declaration files for .vue files

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 93.1%
  • JavaScript 6.9%