Просмотр исходного кода

test: all features except transition pass

Evan You 3 лет назад
Родитель
Сommit
73bcd07194

+ 0 - 1
.gitignore

@@ -20,4 +20,3 @@ packages/vue-template-compiler/build.js
 packages/vue-template-compiler/browser.js
 .vscode
 dist
-debug.spec.ts

+ 4 - 2
test/helpers/to-have-warned.ts

@@ -3,7 +3,9 @@ import { SpyInstance } from 'vitest'
 expect.extend({
   toHaveBeenWarned(received: string) {
     asserted.add(received)
-    const passed = warn.mock.calls.some((args) => args[0].includes(received))
+    const passed = warn.mock.calls.some((args) =>
+      String(args[0]).includes(received)
+    )
     if (passed) {
       return {
         pass: true,
@@ -102,7 +104,7 @@ afterEach(() => {
     .map((args) => args[0])
     .filter((received) => {
       return !assertedArray.some((assertedMsg) => {
-        return received.includes(assertedMsg)
+        return String(received).includes(assertedMsg)
       })
     })
   warn.mockRestore()

+ 2 - 2
test/ssr/ssr-bundle-render.spec.ts

@@ -131,7 +131,7 @@ function createAssertions (runInNewContext) {
         expect(err).toBeNull()
         expect(res).toBe(expected)
         expect(get).toHaveBeenCalledWith(key)
-        const setArgs = set.calls.argsFor(0)
+        const setArgs = set.mock.calls[0]
         expect(setArgs[0]).toBe(key)
         expect(setArgs[1].html).toBe(expected)
         expect(cache[key].html).toBe(expected)
@@ -178,7 +178,7 @@ function createAssertions (runInNewContext) {
         expect(res).toBe(expected)
         expect(has).toHaveBeenCalledWith(key)
         expect(get).not.toHaveBeenCalled()
-        const setArgs = set.calls.argsFor(0)
+        const setArgs = set.mock.calls[0]
         expect(setArgs[0]).toBe(key)
         expect(setArgs[1].html).toBe(expected)
         expect(cache[key].html).toBe(expected)

+ 3 - 4
test/unit/features/debug.spec.ts

@@ -3,7 +3,6 @@ import { formatComponentName, warn } from 'core/util/debug'
 
 describe('Debug utilities', () => {
   it('properly format component names', () => {
-    // @ts-expect-error
     const vm = new Vue()
     expect(formatComponentName(vm)).toBe('<Root>')
 
@@ -84,15 +83,15 @@ found in
 
   describe('warn', () => {
     const msg = 'message'
-    // @ts-expect-error
     const vm = new Vue()
 
     it('calls warnHandler if warnHandler is set', () => {
-      Vue.config.warnHandler = vi.fn()
+      const spy = Vue.config.warnHandler = vi.fn()
 
       warn(msg, vm)
 
-      expect(Vue.config.warnHandler).toHaveBeenCalledWith(msg, vm, jasmine.any(String))
+      expect(spy.mock.calls[0][0]).toBe(msg)
+      expect(spy.mock.calls[0][1]).toBe(vm)
 
       // @ts-expect-error
       Vue.config.warnHandler = null

+ 1 - 2
test/unit/features/error-handling.spec.ts

@@ -152,7 +152,7 @@ describe('Error handling', () => {
     const spy = Vue.config.errorHandler = vi.fn()
     const vm = createTestInstance(components.render)
 
-    const args = spy.calls.argsFor(0)
+    const args = spy.mock.calls[0]
     expect(args[0].toString()).toContain('Error: render') // error
     expect(args[1]).toBe(vm.$refs.child) // vm
     expect(args[2]).toContain('render') // description
@@ -170,7 +170,6 @@ describe('Error handling', () => {
     Vue.nextTick(() => {
       expect(spy).toHaveBeenCalledWith(err1, undefined, 'nextTick')
 
-      // @ts-expect-error
       const vm = new Vue()
       vm.$nextTick(() => { throw err2 })
       Vue.nextTick(() => {

+ 0 - 2
test/unit/features/instance/init.spec.ts

@@ -2,13 +2,11 @@ import Vue from 'vue'
 
 describe('Initialization', () => {
   it('without new', () => {
-    // @ts-expect-error
     try { Vue() } catch (e) {}
     expect('Vue is a constructor and should be called with the `new` keyword').toHaveBeenWarned()
   })
 
   it('with new', () => {
-    // @ts-expect-error
     expect(new Vue() instanceof Vue).toBe(true)
   })
 })

+ 1 - 2
test/unit/features/instance/methods-events.spec.ts

@@ -3,8 +3,7 @@ import Vue from 'vue'
 describe('Instance methods events', () => {
   let vm, spy
   beforeEach(() => {
-    // @ts-expect-error
-    const vm = new Vue()
+    vm = new Vue({})
     spy = vi.fn()
   })
 

+ 2 - 2
test/unit/features/instance/methods-lifecycle.spec.ts

@@ -35,13 +35,13 @@ describe('Instance methods lifecycle', () => {
     })
 
     it('Dep.target should be undefined in lifecycle', () => {
-      const vm = new Vue({
+      new Vue({
         template: '<div><my-component></my-component></div>',
         components: {
           myComponent: {
             template: '<div>hi</div>',
             mounted () {
-              const _msg = this.msg
+              this.msg
               expect(Dep.target).toBe(undefined)
             },
             computed: {

+ 2 - 4
test/unit/features/instance/properties.spec.ts

@@ -27,8 +27,8 @@ describe('Instance properties', () => {
         b () {}
       }
     })
-    expect(typeof vm.$options.methods.a).toBe('function')
-    expect(typeof vm.$options.methods.b).toBe('function')
+    expect(typeof vm.$options.methods?.a).toBe('function')
+    expect(typeof vm.$options.methods?.b).toBe('function')
   })
 
   it('$root/$children', done => {
@@ -161,7 +161,6 @@ describe('Instance properties', () => {
   })
 
   it('warn mutating $attrs', () => {
-    // @ts-expect-error
     const vm = new Vue()
     vm.$attrs = {}
     expect(`$attrs is readonly`).toHaveBeenWarned()
@@ -197,7 +196,6 @@ describe('Instance properties', () => {
   })
 
   it('warn mutating $listeners', () => {
-    // @ts-expect-error
     const vm = new Vue()
     vm.$listeners = {}
     expect(`$listeners is readonly`).toHaveBeenWarned()

+ 1 - 1
test/unit/features/options/data.spec.ts

@@ -16,7 +16,7 @@ describe('Options data', () => {
   })
 
   it('should merge data properly', () => {
-    const Test: Vue = Vue.extend({
+    const Test = Vue.extend({
       data () {
         return { a: 1 }
       }

+ 7 - 6
test/unit/features/options/directives.spec.ts

@@ -1,3 +1,4 @@
+import { SpyInstanceFn } from 'vitest'
 import Vue from 'vue'
 
 describe('Options directives', () => {
@@ -152,7 +153,7 @@ describe('Options directives', () => {
   })
 
   it('should properly handle same node with different directive sets', done => {
-    const spies = {}
+    const spies: Record<string, SpyInstanceFn> = {}
     const createSpy = name => (spies[name] = vi.fn())
     const vm = new Vue({
       data: {
@@ -249,20 +250,20 @@ describe('Options directives', () => {
 
     const oldEl = vm.$el
     expect(dir.bind.mock.calls.length).toBe(1)
-    expect(dir.bind.calls.argsFor(0)[0]).toBe(oldEl)
+    expect(dir.bind.mock.calls[0][0]).toBe(oldEl)
     expect(dir.inserted.mock.calls.length).toBe(1)
-    expect(dir.inserted.calls.argsFor(0)[0]).toBe(oldEl)
+    expect(dir.inserted.mock.calls[0][0]).toBe(oldEl)
     expect(dir.unbind).not.toHaveBeenCalled()
 
     vm.$refs.child.ok = false
     waitForUpdate(() => {
       expect(vm.$el.tagName).toBe('SPAN')
       expect(dir.bind.mock.calls.length).toBe(2)
-      expect(dir.bind.calls.argsFor(1)[0]).toBe(vm.$el)
+      expect(dir.bind.mock.calls[1][0]).toBe(vm.$el)
       expect(dir.inserted.mock.calls.length).toBe(2)
-      expect(dir.inserted.calls.argsFor(1)[0]).toBe(vm.$el)
+      expect(dir.inserted.mock.calls[1][0]).toBe(vm.$el)
       expect(dir.unbind.mock.calls.length).toBe(1)
-      expect(dir.unbind.calls.argsFor(0)[0]).toBe(oldEl)
+      expect(dir.unbind.mock.calls[0][0]).toBe(oldEl)
     }).then(done)
   })
 

+ 1 - 1
test/unit/features/options/functional.spec.ts

@@ -73,7 +73,7 @@ describe('Options functional', () => {
     document.body.appendChild(vm.$el)
     triggerEvent(vm.$el.children[0], 'click')
     expect(foo).toHaveBeenCalled()
-    expect(foo.calls.argsFor(0)[0].type).toBe('click') // should have click event
+    expect(foo.mock.calls[0][0].type).toBe('click') // should have click event
     triggerEvent(vm.$el.children[0], 'mousedown')
     expect(bar).toHaveBeenCalledWith('bar')
     document.body.removeChild(vm.$el)

+ 1 - 2
test/unit/features/options/lifecycle.spec.ts

@@ -78,8 +78,7 @@ describe('Options lifecycle hooks', () => {
 
     // #3898
     it('should call for manually mounted instance with parent', () => {
-      // @ts-expect-error
-      const vm = new Vue()
+      const parent = new Vue()
       expect(spy).not.toHaveBeenCalled()
       new Vue({
         parent,

+ 7 - 7
test/unit/features/options/mixins.spec.ts

@@ -56,12 +56,12 @@ describe('Options mixins', () => {
     })
     expect(result.a).toBe(1)
     expect(result.b).toBe(1)
-    expect(result.directives.a).toBe(a)
-    expect(result.directives.b).toBe(b)
-    expect(result.directives.c).toBe(c)
-    expect(result.created[0]).toBe(f1)
-    expect(result.created[1]).toBe(f2)
-    expect(result.created[2]).toBe(f3)
+    expect(result.directives?.a).toBe(a)
+    expect(result.directives?.b).toBe(b)
+    expect(result.directives?.c).toBe(c)
+    expect(result.created?.[0]).toBe(f1)
+    expect(result.created?.[1]).toBe(f2)
+    expect(result.created?.[2]).toBe(f3)
     expect(result.template).toBe('bar')
   })
 
@@ -85,7 +85,7 @@ describe('Options mixins', () => {
         xyz: f3
       }
     })
-    expect(result.methods.xyz).toBe(f3)
+    expect(result.methods?.xyz).toBe(f3)
   })
 
   it('should accept constructors as mixins', () => {

+ 1 - 1
test/unit/features/options/name.spec.ts

@@ -32,7 +32,7 @@ describe('Options name', () => {
   it('id should not override given name when using Vue.component', () => {
     const SuperComponent = Vue.component('super-component', {
       name: 'SuperVue'
-    })
+    })!
 
     expect(SuperComponent.options.components['SuperVue']).toEqual(SuperComponent)
     expect(SuperComponent.options.components['super-component']).toEqual(SuperComponent)

+ 30 - 30
test/unit/features/options/props.spec.ts

@@ -146,7 +146,7 @@ describe('Options props', () => {
   })
 
   describe('assertions', () => {
-    function makeInstance (value, type, validator, required) {
+    function makeInstance (value, type, validator?, required?) {
       return new Vue({
         template: '<test :test="val"></test>',
         data: {
@@ -169,56 +169,56 @@ describe('Options props', () => {
 
     it('string', () => {
       makeInstance('hello', String)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       makeInstance(123, String)
       expect('Expected String with value "123", got Number with value 123').toHaveBeenWarned()
     })
 
     it('number', () => {
       makeInstance(123, Number)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       makeInstance('123', Number)
       expect('Expected Number with value 123, got String with value "123"').toHaveBeenWarned()
     })
 
     it('number & boolean', () => {
       makeInstance(123, Number)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       makeInstance(false, Number)
       expect('Expected Number, got Boolean with value false').toHaveBeenWarned()
     })
 
     it('string & boolean', () => {
       makeInstance('hello', String)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       makeInstance(true, String)
       expect('Expected String, got Boolean with value true').toHaveBeenWarned()
     })
 
     it('boolean', () => {
       makeInstance(true, Boolean)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       makeInstance('123', Boolean)
       expect('Expected Boolean, got String with value "123"').toHaveBeenWarned()
     })
 
     it('function', () => {
       makeInstance(() => {}, Function)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       makeInstance(123, Function)
       expect('Expected Function, got Number with value 123').toHaveBeenWarned()
     })
 
     it('object', () => {
       makeInstance({}, Object)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       makeInstance([], Object)
       expect('Expected Object, got Array').toHaveBeenWarned()
     })
 
     it('array', () => {
       makeInstance([], Array)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       makeInstance({}, Array)
       expect('Expected Array, got Object').toHaveBeenWarned()
     })
@@ -226,18 +226,18 @@ describe('Options props', () => {
     it('primitive wrapper objects', () => {
       /* eslint-disable no-new-wrappers */
       makeInstance(new String('s'), String)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       makeInstance(new Number(1), Number)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       makeInstance(new Boolean(true), Boolean)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       /* eslint-enable no-new-wrappers */
     })
 
     if (hasSymbol) {
       it('symbol', () => {
         makeInstance(Symbol('foo'), Symbol)
-        expect(console.error.mock.calls.length).toBe(0)
+        expect((console.error as any).mock.calls.length).toBe(0)
         makeInstance({}, Symbol)
         expect('Expected Symbol, got Object').toHaveBeenWarned()
       })
@@ -257,7 +257,7 @@ describe('Options props', () => {
       /* global BigInt */
       it('bigint', () => {
         makeInstance(BigInt(100), BigInt)
-        expect(console.error.mock.calls.length).toBe(0)
+        expect((console.error as any).mock.calls.length).toBe(0)
         makeInstance({}, BigInt)
         expect('Expected BigInt, got Object').toHaveBeenWarned()
       })
@@ -266,28 +266,28 @@ describe('Options props', () => {
     it('custom constructor', () => {
       function Class () {}
       makeInstance(new Class(), Class)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       makeInstance({}, Class)
       expect('type check failed').toHaveBeenWarned()
     })
 
     it('multiple types', () => {
       makeInstance([], [Array, Number, Boolean])
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       makeInstance({}, [Array, Number, Boolean])
       expect('Expected Array, Number, Boolean, got Object').toHaveBeenWarned()
     })
 
     it('custom validator', () => {
       makeInstance(123, null, v => v === 123)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       makeInstance(123, null, v => v === 234)
       expect('custom validator check failed').toHaveBeenWarned()
     })
 
     it('type check + custom validator', () => {
       makeInstance(123, Number, v => v === 123)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       makeInstance(123, Number, v => v === 234)
       expect('custom validator check failed').toHaveBeenWarned()
       makeInstance(123, String, v => v === 123)
@@ -296,7 +296,7 @@ describe('Options props', () => {
 
     it('multiple types + custom validator', () => {
       makeInstance(123, [Number, String, Boolean], v => v === 123)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       makeInstance(123, [Number, String, Boolean], v => v === 234)
       expect('custom validator check failed').toHaveBeenWarned()
       makeInstance(123, [String, Boolean], v => v === 123)
@@ -305,31 +305,31 @@ describe('Options props', () => {
 
     it('optional with type + null/undefined', () => {
       makeInstance(undefined, String)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       makeInstance(null, String)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
     })
 
     it('required with type + null/undefined', () => {
       makeInstance(undefined, String, null, true)
-      expect(console.error.mock.calls.length).toBe(1)
+      expect((console.error as any).mock.calls.length).toBe(1)
       expect('Expected String').toHaveBeenWarned()
       makeInstance(null, Boolean, null, true)
-      expect(console.error.mock.calls.length).toBe(2)
+      expect((console.error as any).mock.calls.length).toBe(2)
       expect('Expected Boolean').toHaveBeenWarned()
     })
 
     it('optional prop of any type (type: true or prop: true)', () => {
       makeInstance(1, true)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       makeInstance('any', true)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       makeInstance({}, true)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       makeInstance(undefined, true)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
       makeInstance(null, true)
-      expect(console.error.mock.calls.length).toBe(0)
+      expect((console.error as any).mock.calls.length).toBe(0)
     })
   })
 
@@ -468,7 +468,7 @@ describe('Options props', () => {
         }
       }
     }).$mount()
-    expect(console.error.mock.calls.length).toBe(0)
+    expect((console.error as any).mock.calls.length).toBe(0)
   })
 
   // #3453
@@ -565,7 +565,7 @@ describe('Options props', () => {
   })
 
   it('should warn when a prop type is not a constructor', () => {
-    const vm = new Vue({
+    new Vue({
       template: '<div>{{a}}</div>',
       props: {
         a: {

+ 0 - 1
test/unit/features/options/render.spec.ts

@@ -33,7 +33,6 @@ describe('Options render', () => {
   })
 
   it('should warn non `render` option and non `template` option', () => {
-    // @ts-expect-error
     new Vue().$mount()
     expect('Failed to mount component: template or render function not defined.').toHaveBeenWarned()
   })

+ 1 - 2
test/unit/features/options/watch.spec.ts

@@ -1,6 +1,5 @@
 import Vue from 'vue'
 import testObjectOption from '../../../helpers/test-object-option'
-import { finished } from 'stream';
 
 describe('Options watch', () => {
   let spy
@@ -163,7 +162,7 @@ describe('Options watch', () => {
   })
 
   it('should not warn proper usage', () => {
-    const vm = new Vue({
+    new Vue({
       data: {
         foo: { _bar: 1 }, // element has such watchers...
         prop1: 123

+ 0 - 1
test/unit/modules/observer/observer.spec.ts

@@ -14,7 +14,6 @@ describe('Observer', () => {
     const ob1 = observe(1)
     expect(ob1).toBeUndefined()
     // avoid vue instance
-    // @ts-expect-error
     const ob2 = observe(new Vue())
     expect(ob2).toBeUndefined()
     // avoid frozen objects

+ 5 - 15
types/tsconfig.json

@@ -2,26 +2,16 @@
   "compilerOptions": {
     "target": "es5",
     "experimentalDecorators": true,
-    "lib": [
-      "dom",
-      "es2015"
-    ],
-    "types": [
-      "node",
-      "jasmine",
-      "webpack-env"
-    ],
+    "lib": ["dom", "es2015"],
+    "types": ["node"],
     "module": "commonjs",
     "strict": true,
     "noEmit": true,
     "baseUrl": ".",
     "paths": {
       "vue": ["../index.d.ts"]
-    },
+    }
   },
-  "include": [
-    "./*.d.ts",
-    "*.ts"
-  ],
+  "include": ["./*.d.ts", "*.ts"],
   "compileOnSave": false
-}
+}

+ 94 - 93
typescript/component.d.ts

@@ -1,113 +1,114 @@
-import type VNode from "../src/core/vdom/vnode";
-import type Watcher from "../src/core/observer/watcher";
-import { ComponentOptions } from "./options";
-import { ScopedSlotsData, VNodeChildren, VNodeData } from "./vnode";
+import type VNode from '../src/core/vdom/vnode'
+import type Watcher from '../src/core/observer/watcher'
+import { ComponentOptions } from './options'
+import { ScopedSlotsData, VNodeChildren, VNodeData } from './vnode'
 
 // TODO this should be using the same as /component/
 
-declare class Component {
+export declare class Component {
+  constructor(options?: any)
   // constructor information
-  static cid: number;
-  static options: Record<string, any>;
+  static cid: number
+  static options: Record<string, any>
   // extend
-  static extend: (options: Record<string, any>) => Function;
-  static superOptions: Record<string, any>;
-  static extendOptions: Record<string, any>;
-  static sealedOptions: Record<string, any>;
-  static super: Component;
+  static extend: (options: Record<string, any>) => typeof Component
+  static superOptions: Record<string, any>
+  static extendOptions: Record<string, any>
+  static sealedOptions: Record<string, any>
+  static super: Component
   // assets
   static directive: (
     id: string,
     def?: Function | Record<string, any>
-  ) => Function | Record<string, any> | void;
+  ) => Function | Record<string, any> | void
   static component: (
     id: string,
     def?: Component | Record<string, any>
-  ) => Component;
-  static filter: (id: string, def?: Function) => Function | void;
+  ) => Component
+  static filter: (id: string, def?: Function) => Function | void
   // functional context constructor
-  static FunctionalRenderContext: Function;
+  static FunctionalRenderContext: Function
 
   // public properties
-  $el: any; // so that we can attach __vue__ to it
-  $data: Record<string, any>;
-  $props: Record<string, any>;
-  $options: ComponentOptions;
-  $parent: Component | undefined;
-  $root: Component;
-  $children: Array<Component>;
+  $el: any // so that we can attach __vue__ to it
+  $data: Record<string, any>
+  $props: Record<string, any>
+  $options: ComponentOptions
+  $parent: Component | undefined
+  $root: Component
+  $children: Array<Component>
   $refs: {
-    [key: string]: Component | Element | Array<Component | Element> | undefined;
-  };
-  $slots: { [key: string]: Array<VNode> };
-  $scopedSlots: { [key: string]: () => VNodeChildren };
-  $vnode: VNode; // the placeholder node for the component in parent's render tree
-  $attrs: { [key: string]: string };
-  $listeners: Record<string, Function | Array<Function>>;
-  $isServer: boolean;
+    [key: string]: Component | Element | Array<Component | Element> | undefined
+  }
+  $slots: { [key: string]: Array<VNode> }
+  $scopedSlots: { [key: string]: () => VNodeChildren }
+  $vnode: VNode // the placeholder node for the component in parent's render tree
+  $attrs: { [key: string]: string }
+  $listeners: Record<string, Function | Array<Function>>
+  $isServer: boolean
 
   // public methods
-  $mount: (el?: Element | string, hydrating?: boolean) => Component;
-  $forceUpdate: () => void;
-  $destroy: () => void;
+  $mount: (el?: Element | string, hydrating?: boolean) => Component
+  $forceUpdate: () => void
+  $destroy: () => void
   $set: <T>(
     target: Record<string, any> | Array<T>,
     key: string | number,
     val: T
-  ) => T;
+  ) => T
   $delete: <T>(
     target: Record<string, any> | Array<T>,
     key: string | number
-  ) => void;
+  ) => void
   $watch: (
     expOrFn: string | Function,
     cb: Function,
     options?: Record<string, any>
-  ) => Function;
-  $on: (event: string | Array<string>, fn: Function) => Component;
-  $once: (event: string, fn: Function) => Component;
-  $off: (event?: string | Array<string>, fn?: Function) => Component;
-  $emit: (event: string, ...args: Array<any>) => Component;
-  $nextTick: (fn: Function) => void | Promise<any>;
+  ) => Function
+  $on: (event: string | Array<string>, fn: Function) => Component
+  $once: (event: string, fn: Function) => Component
+  $off: (event?: string | Array<string>, fn?: Function) => Component
+  $emit: (event: string, ...args: Array<any>) => Component
+  $nextTick: (fn: Function) => void | Promise<any>
   $createElement: (
     tag?: string | Component,
     data?: Record<string, any>,
     children?: VNodeChildren
-  ) => VNode;
+  ) => VNode
 
   // private properties
-  _uid: number | string;
-  _name: string; // this only exists in dev mode
-  _isVue: true;
-  _self: Component;
-  _renderProxy: Component;
-  _renderContext?: Component;
-  _watcher: Watcher | null;
-  _watchers: Array<Watcher>;
-  _computedWatchers: { [key: string]: Watcher };
-  _data: Record<string, any>;
-  _props: Record<string, any>;
-  _events: Record<string, any>;
-  _inactive: boolean | null;
-  _directInactive: boolean;
-  _isMounted: boolean;
-  _isDestroyed: boolean;
-  _isBeingDestroyed: boolean;
-  _vnode?: VNode | null; // self root node
-  _staticTrees?: Array<VNode> | null; // v-once cached trees
-  _hasHookEvent: boolean;
-  _provided?: Record<string, any>;
+  _uid: number | string
+  _name: string // this only exists in dev mode
+  _isVue: true
+  _self: Component
+  _renderProxy: Component
+  _renderContext?: Component
+  _watcher: Watcher | null
+  _watchers: Array<Watcher>
+  _computedWatchers: { [key: string]: Watcher }
+  _data: Record<string, any>
+  _props: Record<string, any>
+  _events: Record<string, any>
+  _inactive: boolean | null
+  _directInactive: boolean
+  _isMounted: boolean
+  _isDestroyed: boolean
+  _isBeingDestroyed: boolean
+  _vnode?: VNode | null // self root node
+  _staticTrees?: Array<VNode> | null // v-once cached trees
+  _hasHookEvent: boolean
+  _provided?: Record<string, any>
   // _virtualComponents?: { [key: string]: Component };
 
   // private methods
 
   // lifecycle
-  _init: Function;
-  _mount: (el?: Element | void, hydrating?: boolean) => Component;
-  _update: (vnode: VNode, hydrating?: boolean) => void;
+  _init: Function
+  _mount: (el?: Element | void, hydrating?: boolean) => Component
+  _update: (vnode: VNode, hydrating?: boolean) => void
 
   // rendering
-  _render: () => VNode;
+  _render: () => VNode
 
   __patch__: (
     a: Element | VNode | void | null,
@@ -116,7 +117,7 @@ declare class Component {
     removeOnly?: boolean,
     parentElm?: any,
     refElm?: any
-  ) => any;
+  ) => any
 
   // createElement
 
@@ -126,38 +127,38 @@ declare class Component {
     data?: VNodeData,
     children?: VNodeChildren,
     normalizationType?: number
-  ) => VNode | void;
+  ) => VNode | void
 
   // renderStatic
-  _m: (index: number, isInFor?: boolean) => VNode | VNodeChildren;
+  _m: (index: number, isInFor?: boolean) => VNode | VNodeChildren
   // markOnce
   _o: (
     vnode: VNode | Array<VNode>,
     index: number,
     key: string
-  ) => VNode | VNodeChildren;
+  ) => VNode | VNodeChildren
   // toString
-  _s: (value: any) => string;
+  _s: (value: any) => string
   // text to VNode
-  _v: (value: string | number) => VNode;
+  _v: (value: string | number) => VNode
   // toNumber
-  _n: (value: string) => number | string;
+  _n: (value: string) => number | string
   // empty vnode
-  _e: () => VNode;
+  _e: () => VNode
   // loose equal
-  _q: (a: any, b: any) => boolean;
+  _q: (a: any, b: any) => boolean
   // loose indexOf
-  _i: (arr: Array<any>, val: any) => number;
+  _i: (arr: Array<any>, val: any) => number
   // resolveFilter
-  _f: (id: string) => Function;
+  _f: (id: string) => Function
   // renderList
-  _l: (val: any, render: Function) => Array<VNode> | null;
+  _l: (val: any, render: Function) => Array<VNode> | null
   // renderSlot
   _t: (
     name: string,
     fallback?: Array<VNode>,
     props?: Record<string, any>
-  ) => Array<VNode> | null;
+  ) => Array<VNode> | null
   // apply v-bind object
   _b: (
     data: any,
@@ -165,32 +166,32 @@ declare class Component {
     value: any,
     asProp: boolean,
     isSync?: boolean
-  ) => VNodeData;
+  ) => VNodeData
   // apply v-on object
-  _g: (data: any, value: any) => VNodeData;
+  _g: (data: any, value: any) => VNodeData
   // check custom keyCode
   _k: (
     eventKeyCode: number,
     key: string,
     builtInAlias?: number | Array<number>,
     eventKeyName?: string
-  ) => boolean | null;
+  ) => boolean | null
   // resolve scoped slots
   _u: (
     scopedSlots: ScopedSlotsData,
     res?: Record<string, any>
-  ) => { [key: string]: Function };
+  ) => { [key: string]: Function }
 
   // SSR specific
-  _ssrNode: Function;
-  _ssrList: Function;
-  _ssrEscape: Function;
-  _ssrAttr: Function;
-  _ssrAttrs: Function;
-  _ssrDOMProps: Function;
-  _ssrClass: Function;
+  _ssrNode: Function
+  _ssrList: Function
+  _ssrEscape: Function
+  _ssrAttr: Function
+  _ssrAttrs: Function
+  _ssrDOMProps: Function
+  _ssrClass: Function
   _ssrStyle: Function;
 
   // allow dynamic method registration
-  [key: string]: any;
+  [key: string]: any
 }

+ 26 - 21
typescript/global-api.d.ts

@@ -1,29 +1,34 @@
-import { Config } from "../src/core/config";
-import { Component } from "./component";
+import { Config } from '../src/core/config'
+import { Component } from './component'
 
 declare interface GlobalAPI {
-  (options: any): void;
-  cid: number;
-  options: Record<string, any>;
-  config: Config;
-  util: Object;
+  // new(options?: any): Component
+  (options?: any): void
+  cid: number
+  options: Record<string, any>
+  config: Config
+  util: Object
 
-  extend: (options: Object) => Component;
-  set: <T>(target: Object | Array<T>, key: string | number, value: T) => T;
-  delete: <T>(target: Object | Array<T>, key: string | number) => void;
-  nextTick: (fn: Function, context?: Object) => void | Promise<any>;
-  use: (plugin: Function | Object) => GlobalAPI;
-  mixin: (mixin: Object) => GlobalAPI;
-  compile: (
-    template: string
-  ) => { render: Function; staticRenderFns: Array<Function> };
+  extend: (options: Object) => typeof Component
+  set: <T>(target: Object | Array<T>, key: string | number, value: T) => T
+  delete: <T>(target: Object | Array<T>, key: string | number) => void
+  nextTick: (fn: Function, context?: Object) => void | Promise<any>
+  use: (plugin: Function | Object) => GlobalAPI
+  mixin: (mixin: Object) => GlobalAPI
+  compile: (template: string) => {
+    render: Function
+    staticRenderFns: Array<Function>
+  }
 
-  directive: (id: string, def?: Function | Object) => Function | Object | void;
-  component: (id: string, def?: Component | Object) => Component;
-  filter: (id: string, def?: Function) => Function | void;
+  directive: (id: string, def?: Function | Object) => Function | Object | void
+  component: (
+    id: string,
+    def?: typeof Component | Object
+  ) => typeof Component | void
+  filter: (id: string, def?: Function) => Function | void
 
-  observable: <T>(value: T) => T;
+  observable: <T>(value: T) => T
 
   // allow dynamic method registration
-  [key: string]: any;
+  [key: string]: any
 }

+ 2 - 0
typescript/options.d.ts

@@ -12,6 +12,8 @@ declare type InternalComponentOptions = {
 type InjectKey = string | Symbol;
 
 declare type ComponentOptions = {
+  [key: string]: any
+
   componentId?: string;
 
   // data