diff --git a/README.md b/README.md index 84927c7..0f1ce67 100644 --- a/README.md +++ b/README.md @@ -200,7 +200,21 @@ new Vue({ }) ``` -In TypeScript, all built-in lifecycle hools and special methods are declared in the component instance type to enable auto-complete in editors. +### Enabling Custom Hooks Auto-complete in TypeScript + +vue-class-component provides a built-in hooks type, which enables auto-complete for `data`, `render` and other lifecycle hooks in class component declarations, for TypeScript. To enable it, you need to import hooks type located at `vue-class-component/hooks`. + +```ts +// main.ts +import 'vue-class-component/hooks' // import hooks type to enable auto-complete +import Vue from 'vue' +import App from './App.vue' + +new Vue({ + render: h => h(App) +}).$mount('#app') +``` + If you want to make it work with custom hooks, you can manually add it by yourself: ```ts diff --git a/src/lifecycle.ts b/hooks.d.ts similarity index 100% rename from src/lifecycle.ts rename to hooks.d.ts diff --git a/hooks.js b/hooks.js new file mode 100644 index 0000000..b0f0b98 --- /dev/null +++ b/hooks.js @@ -0,0 +1 @@ +// Dummy empty file to avoid import error when using hooks.d.ts diff --git a/package.json b/package.json index caa9168..b7bc69f 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,8 @@ "typings": "lib/index.d.ts", "files": [ "dist", - "lib" + "lib", + "hooks.d.ts" ], "scripts": { "build": "npm run build:ts && npm run build:main", diff --git a/src/index.ts b/src/index.ts index 837e326..d2b955b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,3 @@ -import './lifecycle' import Vue, { ComponentOptions } from 'vue' import { VueClass } from './declarations' import { componentFactory, $internalHooks } from './component'