Skip to content

Commit 8632bc6

Browse files
ktsnyyx990803
authored andcommitted
feat: adapt to the new vue typings (#132)
1 parent 0ca7db0 commit 8632bc6

File tree

10 files changed

+658
-459
lines changed

10 files changed

+658
-459
lines changed

example/tsconfig.json

+2-6
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@
77
],
88
"module": "commonjs",
99
"moduleResolution": "node",
10-
"isolatedModules": false,
1110
"experimentalDecorators": true,
12-
"noImplicitAny": true,
13-
"noImplicitThis": true,
14-
"strictNullChecks": true,
15-
"removeComments": true,
11+
"strict": true,
1612
"suppressImplicitAnyIndexErrors": true,
17-
"allowSyntheticDefaultImports": true
13+
"removeComments": true
1814
},
1915
"include": [
2016
"./**/*.ts"

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@
5252
"ts-loader": "^2.2.1",
5353
"typescript": "^2.5.2",
5454
"uglify-js": "^3.0.22",
55-
"vue": "^2.3.4",
55+
"vue": "github:vuejs/vue#dev",
5656
"vue-loader": "^13.0.0",
57-
"vue-template-compiler": "^2.3.4",
57+
"vue-template-compiler": "^2.4.4",
5858
"webpack": "^3.0.0"
5959
}
6060
}

src/component.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ export const $internalHooks = [
1818
]
1919

2020
export function componentFactory (
21-
Component: VueClass,
22-
options: ComponentOptions<any> = {}
23-
): VueClass {
21+
Component: VueClass<Vue>,
22+
options: ComponentOptions<any, any, any, any> = {}
23+
): VueClass<Vue> {
2424
options.name = options.name || (Component as any)._componentTag || (Component as any).name
2525
// prototype props.
2626
const proto = Component.prototype
@@ -62,7 +62,7 @@ export function componentFactory (
6262
// find super
6363
const superProto = Object.getPrototypeOf(Component.prototype)
6464
const Super = superProto instanceof Vue
65-
? superProto.constructor as VueClass
65+
? superProto.constructor as VueClass<Vue>
6666
: Vue
6767
return Super.extend(options)
6868
}

src/data.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Vue from 'vue'
22
import { VueClass } from './declarations'
33
import { noop, warn } from './util'
44

5-
export function collectDataFromConstructor (vm: Vue, Component: VueClass) {
5+
export function collectDataFromConstructor (vm: Vue, Component: VueClass<Vue>) {
66
// override _init to prevent to init as Vue instance
77
Component.prototype._init = function (this: Vue) {
88
// proxy to actual vm

src/declarations.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import Vue from 'vue'
1+
import Vue, { ComponentOptions } from 'vue'
22

3-
export type VueClass = { new (): Vue } & typeof Vue
3+
export type VueClass<V extends Vue> = { new (...args: any[]): V } & typeof Vue
44

5-
export type DecoratedClass = VueClass & {
5+
export type DecoratedClass = VueClass<Vue> & {
66
// Property, method and parameter decorators created by `createDecorator` helper
77
// will enqueue functions that update component options for lazy processing.
88
// They will be executed just before creating component constructor.
9-
__decorators__?: ((options: Vue.ComponentOptions<Vue>) => void)[]
9+
__decorators__?: ((options: ComponentOptions<any, any, any, any>) => void)[]
1010
}

src/index.ts

+4-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@ import { componentFactory, $internalHooks } from './component'
44

55
export { createDecorator } from './util'
66

7-
function Component <U extends Vue>(options: ComponentOptions<U>): <V extends VueClass>(target: V) => V
8-
function Component <V extends VueClass>(target: V): V
9-
function Component <V extends VueClass, U extends Vue>(
10-
options: ComponentOptions<U> | V
11-
): any {
7+
function Component <V extends Vue>(options: ComponentOptions<any, any, any, any> & ThisType<V>): <VC extends VueClass<V>>(target: VC) => VC
8+
function Component <VC extends VueClass<Vue>>(target: VC): VC
9+
function Component (options: ComponentOptions<any, any, any, any> | VueClass<Vue>): any {
1210
if (typeof options === 'function') {
1311
return componentFactory(options)
1412
}
15-
return function (Component: V) {
13+
return function (Component: VueClass<Vue>) {
1614
return componentFactory(Component, options)
1715
}
1816
}

src/util.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import { DecoratedClass } from './declarations'
44
export const noop = () => {}
55

66
export function createDecorator (
7-
factory: (options: ComponentOptions<Vue>, key: string) => void
7+
factory: (options: ComponentOptions<any, any, any, any>, key: string) => void
88
): (target: Vue, key: string) => void
99
export function createDecorator (
10-
factory: (options: ComponentOptions<Vue>, key: string, index: number) => void
10+
factory: (options: ComponentOptions<any, any, any, any>, key: string, index: number) => void
1111
): (target: Vue, key: string, index: number) => void
1212
export function createDecorator (
13-
factory: (options: ComponentOptions<Vue>, key: string, index: number) => void
13+
factory: (options: ComponentOptions<any, any, any, any>, key: string, index: number) => void
1414
): (target: Vue, key: string, index: any) => void {
1515
return (target, key, index) => {
1616
const Ctor = target.constructor as DecoratedClass

test/test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Component, { createDecorator } from '../lib'
22
import { expect } from 'chai'
3-
import Vue from 'vue'
3+
import Vue, { ComputedOptions } from 'vue'
44

55
describe('vue-class-component', () => {
66

@@ -197,7 +197,7 @@ describe('vue-class-component', () => {
197197
const NoCache = createDecorator((options, key) => {
198198
// options should have computed and methods etc.
199199
// that specified by class property accessors and methods
200-
const computedOption = options.computed![key] as Vue.ComputedOptions<Vue>
200+
const computedOption = options.computed![key] as ComputedOptions<Vue>
201201
computedOption.cache = false
202202
})
203203

tsconfig.json

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,11 @@
88
"module": "es2015",
99
"moduleResolution": "node",
1010
"outDir": "lib",
11-
"isolatedModules": false,
1211
"experimentalDecorators": true,
1312
"declaration": true,
14-
"noImplicitAny": true,
15-
"noImplicitThis": true,
16-
"strictNullChecks": true,
17-
"removeComments": true,
13+
"strict": true,
1814
"suppressImplicitAnyIndexErrors": true,
19-
"allowSyntheticDefaultImports": true
15+
"removeComments": true
2016
},
2117
"include": [
2218
"src/**/*.ts"

0 commit comments

Comments
 (0)