From 28c19e4e86f480ad688908a3c55863607f8cd69e Mon Sep 17 00:00:00 2001 From: ktsn Date: Sun, 12 Jan 2020 15:46:00 +0900 Subject: [PATCH 1/2] fix: avoid breakage not to auto augment hooks type --- README.md | 16 +++++++++++++++- src/lifecycle.ts => hooks.d.ts | 0 package.json | 3 ++- src/index.ts | 1 - 4 files changed, 17 insertions(+), 3 deletions(-) rename src/lifecycle.ts => hooks.d.ts (100%) 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/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' From 92ea687c4b175d1e30322cb7a92fa77d9bc33968 Mon Sep 17 00:00:00 2001 From: ktsn Date: Sun, 12 Jan 2020 16:02:41 +0900 Subject: [PATCH 2/2] fix: add dummy hooks.js --- hooks.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 hooks.js 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