From 4c376fc6315768e24f7ba7c8a2a56ba269300466 Mon Sep 17 00:00:00 2001 From: ktsn Date: Tue, 15 Aug 2017 23:00:37 +0900 Subject: [PATCH 1/4] feat: adapt the new vue typings BREAKING CHANGE: The old Vue typings is no longer compatible --- example/tsconfig.json | 8 ++------ package.json | 6 +++--- src/component.ts | 8 ++++---- src/data.ts | 2 +- src/declarations.ts | 8 ++++---- src/index.ts | 10 ++++------ src/util.ts | 6 +++--- test/test.ts | 4 ++-- tsconfig.json | 8 ++------ yarn.lock | 18 +++++++++--------- 10 files changed, 34 insertions(+), 44 deletions(-) diff --git a/example/tsconfig.json b/example/tsconfig.json index 083aab7..db64d83 100644 --- a/example/tsconfig.json +++ b/example/tsconfig.json @@ -7,14 +7,10 @@ ], "module": "commonjs", "moduleResolution": "node", - "isolatedModules": false, "experimentalDecorators": true, - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "removeComments": true, + "strict": true, "suppressImplicitAnyIndexErrors": true, - "allowSyntheticDefaultImports": true + "removeComments": true }, "include": [ "./**/*.ts" diff --git a/package.json b/package.json index 412ad83..f637906 100644 --- a/package.json +++ b/package.json @@ -50,11 +50,11 @@ "rollup-plugin-replace": "^1.1.1", "testdouble": "^3.2.1", "ts-loader": "^2.2.1", - "typescript": "^2.4.1", + "typescript": "^2.4.2", "uglify-js": "^3.0.22", - "vue": "^2.3.4", + "vue": "DanielRosenwasser/vue#e4a8545", "vue-loader": "^13.0.0", - "vue-template-compiler": "^2.3.4", + "vue-template-compiler": "^2.4.2", "webpack": "^3.0.0" } } diff --git a/src/component.ts b/src/component.ts index 4386e24..fbc9ae7 100644 --- a/src/component.ts +++ b/src/component.ts @@ -18,9 +18,9 @@ export const $internalHooks = [ ] export function componentFactory ( - Component: VueClass, - options: ComponentOptions = {} -): VueClass { + Component: VueClass, + options: ComponentOptions = {} +): VueClass { options.name = options.name || (Component as any)._componentTag || (Component as any).name // prototype props. const proto = Component.prototype @@ -62,7 +62,7 @@ export function componentFactory ( // find super const superProto = Object.getPrototypeOf(Component.prototype) const Super = superProto instanceof Vue - ? superProto.constructor as VueClass + ? superProto.constructor as VueClass : Vue return Super.extend(options) } diff --git a/src/data.ts b/src/data.ts index 6c245cc..91e641a 100644 --- a/src/data.ts +++ b/src/data.ts @@ -2,7 +2,7 @@ import Vue from 'vue' import { VueClass } from './declarations' import { noop, warn } from './util' -export function collectDataFromConstructor (vm: Vue, Component: VueClass) { +export function collectDataFromConstructor (vm: Vue, Component: VueClass) { // override _init to prevent to init as Vue instance Component.prototype._init = function (this: Vue) { // proxy to actual vm diff --git a/src/declarations.ts b/src/declarations.ts index 235962c..7182422 100644 --- a/src/declarations.ts +++ b/src/declarations.ts @@ -1,10 +1,10 @@ -import Vue from 'vue' +import Vue, { ComponentOptions } from 'vue' -export type VueClass = { new (): Vue } & typeof Vue +export type VueClass = { new (...args: any[]): V } & typeof Vue -export type DecoratedClass = VueClass & { +export type DecoratedClass = VueClass & { // Property, method and parameter decorators created by `createDecorator` helper // will enqueue functions that update component options for lazy processing. // They will be executed just before creating component constructor. - __decorators__?: ((options: Vue.ComponentOptions) => void)[] + __decorators__?: ((options: ComponentOptions) => void)[] } diff --git a/src/index.ts b/src/index.ts index 53b5b12..671e535 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,15 +4,13 @@ import { componentFactory, $internalHooks } from './component' export { createDecorator } from './util' -function Component (options: ComponentOptions): (target: V) => V -function Component (target: V): V -function Component ( - options: ComponentOptions | V -): any { +function Component (options: ComponentOptions & ThisType): >(target: VC) => VC +function Component >(target: VC): VC +function Component (options: ComponentOptions | VueClass): any { if (typeof options === 'function') { return componentFactory(options) } - return function (Component: V) { + return function (Component: VueClass) { return componentFactory(Component, options) } } diff --git a/src/util.ts b/src/util.ts index 0dfd7a3..fcd4514 100644 --- a/src/util.ts +++ b/src/util.ts @@ -4,13 +4,13 @@ import { DecoratedClass } from './declarations' export const noop = () => {} export function createDecorator ( - factory: (options: ComponentOptions, key: string) => void + factory: (options: ComponentOptions, key: string) => void ): (target: Vue, key: string) => void export function createDecorator ( - factory: (options: ComponentOptions, key: string, index: number) => void + factory: (options: ComponentOptions, key: string, index: number) => void ): (target: Vue, key: string, index: number) => void export function createDecorator ( - factory: (options: ComponentOptions, key: string, index: number) => void + factory: (options: ComponentOptions, key: string, index: number) => void ): (target: Vue, key: string, index: any) => void { return (target, key, index) => { const Ctor = target.constructor as DecoratedClass diff --git a/test/test.ts b/test/test.ts index 6057ee7..7fd5b52 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1,6 +1,6 @@ import Component, { createDecorator } from '../lib' import { expect } from 'chai' -import Vue from 'vue' +import Vue, { ComputedOptions } from 'vue' describe('vue-class-component', () => { @@ -197,7 +197,7 @@ describe('vue-class-component', () => { const NoCache = createDecorator((options, key) => { // options should have computed and methods etc. // that specified by class property accessors and methods - const computedOption: Vue.ComputedOptions = options.computed![key] + const computedOption: ComputedOptions = options.computed![key] computedOption.cache = false }) diff --git a/tsconfig.json b/tsconfig.json index 60cbf2e..d26a781 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,15 +8,11 @@ "module": "es2015", "moduleResolution": "node", "outDir": "lib", - "isolatedModules": false, "experimentalDecorators": true, "declaration": true, - "noImplicitAny": true, - "noImplicitThis": true, - "strictNullChecks": true, - "removeComments": true, + "strict": true, "suppressImplicitAnyIndexErrors": true, - "allowSyntheticDefaultImports": true + "removeComments": true }, "include": [ "src/**/*.ts" diff --git a/yarn.lock b/yarn.lock index 30319d1..0d6d91a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3292,9 +3292,9 @@ type-detect@^4.0.0: version "4.0.3" resolved "https://registry.yarnpkg.com/type-detect/-/type-detect-4.0.3.tgz#0e3f2670b44099b0b46c284d136a7ef49c74c2ea" -typescript@^2.4.1: - version "2.4.1" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.1.tgz#c3ccb16ddaa0b2314de031e7e6fee89e5ba346bc" +typescript@^2.4.2: + version "2.4.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.4.2.tgz#f8395f85d459276067c988aa41837a8f82870844" uglify-js@^2.8.29: version "2.8.29" @@ -3419,9 +3419,9 @@ vue-style-loader@^3.0.0: hash-sum "^1.0.2" loader-utils "^1.0.2" -vue-template-compiler@^2.3.4: - version "2.3.4" - resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.3.4.tgz#5a88ac2c5e4d5d6218e6aa80e7e221fb7e67894c" +vue-template-compiler@^2.4.2: + version "2.4.2" + resolved "https://registry.yarnpkg.com/vue-template-compiler/-/vue-template-compiler-2.4.2.tgz#5a45d843f148b098f6c1d1e35ac20c4956d30ad1" dependencies: de-indent "^1.0.2" he "^1.1.0" @@ -3430,9 +3430,9 @@ vue-template-es2015-compiler@^1.5.3: version "1.5.3" resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.5.3.tgz#22787de4e37ebd9339b74223bc467d1adee30545" -vue@^2.3.4: - version "2.3.4" - resolved "https://registry.yarnpkg.com/vue/-/vue-2.3.4.tgz#5ec3b87a191da8090bbef56b7cfabd4158038171" +vue@DanielRosenwasser/vue#e4a8545: + version "2.4.2" + resolved "https://codeload.github.com/DanielRosenwasser/vue/tar.gz/e4a8545" watchpack@^1.3.1: version "1.3.1" From 82956c6ba06252b69d6d46e7e37d4e1e23b08e5b Mon Sep 17 00:00:00 2001 From: ktsn Date: Tue, 12 Sep 2017 23:23:36 +0900 Subject: [PATCH 2/4] chore: bump core typings --- package.json | 2 +- test/test.ts | 2 +- yarn.lock | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index f290e5a..d694a3f 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "ts-loader": "^2.2.1", "typescript": "^2.5.2", "uglify-js": "^3.0.22", - "vue": "DanielRosenwasser/vue#e4a8545", + "vue": "github:HerringtonDarkholme/vue#8901752", "vue-loader": "^13.0.0", "vue-template-compiler": "^2.4.2", "webpack": "^3.0.0" diff --git a/test/test.ts b/test/test.ts index a0ab507..9319ffc 100644 --- a/test/test.ts +++ b/test/test.ts @@ -197,7 +197,7 @@ describe('vue-class-component', () => { const NoCache = createDecorator((options, key) => { // options should have computed and methods etc. // that specified by class property accessors and methods - const computedOption = options.computed![key] as Vue.ComputedOptions + const computedOption = options.computed![key] as ComputedOptions computedOption.cache = false }) diff --git a/yarn.lock b/yarn.lock index aa4ee10..e66e6f5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3626,9 +3626,9 @@ vue-template-es2015-compiler@^1.5.3: version "1.5.3" resolved "https://registry.yarnpkg.com/vue-template-es2015-compiler/-/vue-template-es2015-compiler-1.5.3.tgz#22787de4e37ebd9339b74223bc467d1adee30545" -vue@DanielRosenwasser/vue#e4a8545: +"vue@github:HerringtonDarkholme/vue#8901752": version "2.4.2" - resolved "https://codeload.github.com/DanielRosenwasser/vue/tar.gz/e4a8545" + resolved "https://codeload.github.com/HerringtonDarkholme/vue/tar.gz/8901752" watchpack@^1.4.0: version "1.4.0" From c4e1cdb0a1d3080266a0fddfbdfe7330100438f0 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 11 Oct 2017 22:19:07 -0400 Subject: [PATCH 3/4] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d694a3f..3c6af5b 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ "ts-loader": "^2.2.1", "typescript": "^2.5.2", "uglify-js": "^3.0.22", - "vue": "github:HerringtonDarkholme/vue#8901752", + "vue": "github:vuejs/vue#dev", "vue-loader": "^13.0.0", "vue-template-compiler": "^2.4.2", "webpack": "^3.0.0" From a715fd4335bb0c07727c2b8cb72c765710c0e34a Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 11 Oct 2017 22:19:33 -0400 Subject: [PATCH 4/4] Update package.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3c6af5b..caa6f0d 100644 --- a/package.json +++ b/package.json @@ -54,7 +54,7 @@ "uglify-js": "^3.0.22", "vue": "github:vuejs/vue#dev", "vue-loader": "^13.0.0", - "vue-template-compiler": "^2.4.2", + "vue-template-compiler": "^2.4.4", "webpack": "^3.0.0" } }