diff --git a/.gitignore b/.gitignore index 6778e3ad772..1dd81e3fe8b 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,3 @@ packages/vue-template-compiler/build.js packages/vue-template-compiler/browser.js .vscode dist -debug.spec.ts diff --git a/test/helpers/to-have-warned.ts b/test/helpers/to-have-warned.ts index 97eecfd1f34..1a931595eaa 100644 --- a/test/helpers/to-have-warned.ts +++ b/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() diff --git a/test/ssr/ssr-bundle-render.spec.ts b/test/ssr/ssr-bundle-render.spec.ts index a44bc8e1d31..530b5f321f2 100644 --- a/test/ssr/ssr-bundle-render.spec.ts +++ b/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) diff --git a/test/unit/features/debug.spec.ts b/test/unit/features/debug.spec.ts index 4f510e79c77..6e206c0d356 100644 --- a/test/unit/features/debug.spec.ts +++ b/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('') @@ -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 diff --git a/test/unit/features/error-handling.spec.ts b/test/unit/features/error-handling.spec.ts index 7ef5f84ccc5..ba737e616ec 100644 --- a/test/unit/features/error-handling.spec.ts +++ b/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(() => { diff --git a/test/unit/features/instance/init.spec.ts b/test/unit/features/instance/init.spec.ts index 5fda9407c78..62cc06dc22d 100644 --- a/test/unit/features/instance/init.spec.ts +++ b/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) }) }) diff --git a/test/unit/features/instance/methods-events.spec.ts b/test/unit/features/instance/methods-events.spec.ts index 09aa52825f4..a9dd77b219d 100644 --- a/test/unit/features/instance/methods-events.spec.ts +++ b/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() }) diff --git a/test/unit/features/instance/methods-lifecycle.spec.ts b/test/unit/features/instance/methods-lifecycle.spec.ts index 3af73efbb69..19b4727a358 100644 --- a/test/unit/features/instance/methods-lifecycle.spec.ts +++ b/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: '
', components: { myComponent: { template: '
hi
', mounted () { - const _msg = this.msg + this.msg expect(Dep.target).toBe(undefined) }, computed: { diff --git a/test/unit/features/instance/properties.spec.ts b/test/unit/features/instance/properties.spec.ts index 3e4f365335e..fc426ba4ed0 100644 --- a/test/unit/features/instance/properties.spec.ts +++ b/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() diff --git a/test/unit/features/options/data.spec.ts b/test/unit/features/options/data.spec.ts index 0f543b2a9fb..ac431bbd939 100644 --- a/test/unit/features/options/data.spec.ts +++ b/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 } } diff --git a/test/unit/features/options/directives.spec.ts b/test/unit/features/options/directives.spec.ts index 6560e1146a4..824377b3bb9 100644 --- a/test/unit/features/options/directives.spec.ts +++ b/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 = {} 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) }) diff --git a/test/unit/features/options/functional.spec.ts b/test/unit/features/options/functional.spec.ts index eb4c52a7b20..723ba1b6a4c 100644 --- a/test/unit/features/options/functional.spec.ts +++ b/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) diff --git a/test/unit/features/options/lifecycle.spec.ts b/test/unit/features/options/lifecycle.spec.ts index 03f1dec9317..dd4b3e87ad2 100644 --- a/test/unit/features/options/lifecycle.spec.ts +++ b/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, diff --git a/test/unit/features/options/mixins.spec.ts b/test/unit/features/options/mixins.spec.ts index 09be22903f1..8b71b0f355e 100644 --- a/test/unit/features/options/mixins.spec.ts +++ b/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', () => { diff --git a/test/unit/features/options/name.spec.ts b/test/unit/features/options/name.spec.ts index 051ea403064..b982c9fba0e 100644 --- a/test/unit/features/options/name.spec.ts +++ b/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) diff --git a/test/unit/features/options/props.spec.ts b/test/unit/features/options/props.spec.ts index 6a6c1ffde75..6d1978f112c 100644 --- a/test/unit/features/options/props.spec.ts +++ b/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: '', 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: '
{{a}}
', props: { a: { diff --git a/test/unit/features/options/render.spec.ts b/test/unit/features/options/render.spec.ts index 3b73d029dca..736afa2ca4d 100644 --- a/test/unit/features/options/render.spec.ts +++ b/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() }) diff --git a/test/unit/features/options/watch.spec.ts b/test/unit/features/options/watch.spec.ts index 234852a038b..edd298066b9 100644 --- a/test/unit/features/options/watch.spec.ts +++ b/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 diff --git a/test/unit/modules/observer/observer.spec.ts b/test/unit/modules/observer/observer.spec.ts index 698931dcee4..f8341c1719c 100644 --- a/test/unit/modules/observer/observer.spec.ts +++ b/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 diff --git a/types/tsconfig.json b/types/tsconfig.json index 57d9919cc76..ffccdfc70d3 100644 --- a/types/tsconfig.json +++ b/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 -} \ No newline at end of file +} diff --git a/typescript/component.d.ts b/typescript/component.d.ts index c0a0bc9b0c0..0f9c4c616a8 100644 --- a/typescript/component.d.ts +++ b/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; + static cid: number + static options: Record // extend - static extend: (options: Record) => Function; - static superOptions: Record; - static extendOptions: Record; - static sealedOptions: Record; - static super: Component; + static extend: (options: Record) => typeof Component + static superOptions: Record + static extendOptions: Record + static sealedOptions: Record + static super: Component // assets static directive: ( id: string, def?: Function | Record - ) => Function | Record | void; + ) => Function | Record | void static component: ( id: string, def?: Component | Record - ) => 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; - $props: Record; - $options: ComponentOptions; - $parent: Component | undefined; - $root: Component; - $children: Array; + $el: any // so that we can attach __vue__ to it + $data: Record + $props: Record + $options: ComponentOptions + $parent: Component | undefined + $root: Component + $children: Array $refs: { - [key: string]: Component | Element | Array | undefined; - }; - $slots: { [key: string]: Array }; - $scopedSlots: { [key: string]: () => VNodeChildren }; - $vnode: VNode; // the placeholder node for the component in parent's render tree - $attrs: { [key: string]: string }; - $listeners: Record>; - $isServer: boolean; + [key: string]: Component | Element | Array | undefined + } + $slots: { [key: string]: Array } + $scopedSlots: { [key: string]: () => VNodeChildren } + $vnode: VNode // the placeholder node for the component in parent's render tree + $attrs: { [key: string]: string } + $listeners: Record> + $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: ( target: Record | Array, key: string | number, val: T - ) => T; + ) => T $delete: ( target: Record | Array, key: string | number - ) => void; + ) => void $watch: ( expOrFn: string | Function, cb: Function, options?: Record - ) => Function; - $on: (event: string | Array, fn: Function) => Component; - $once: (event: string, fn: Function) => Component; - $off: (event?: string | Array, fn?: Function) => Component; - $emit: (event: string, ...args: Array) => Component; - $nextTick: (fn: Function) => void | Promise; + ) => Function + $on: (event: string | Array, fn: Function) => Component + $once: (event: string, fn: Function) => Component + $off: (event?: string | Array, fn?: Function) => Component + $emit: (event: string, ...args: Array) => Component + $nextTick: (fn: Function) => void | Promise $createElement: ( tag?: string | Component, data?: Record, 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; - _computedWatchers: { [key: string]: Watcher }; - _data: Record; - _props: Record; - _events: Record; - _inactive: boolean | null; - _directInactive: boolean; - _isMounted: boolean; - _isDestroyed: boolean; - _isBeingDestroyed: boolean; - _vnode?: VNode | null; // self root node - _staticTrees?: Array | null; // v-once cached trees - _hasHookEvent: boolean; - _provided?: Record; + _uid: number | string + _name: string // this only exists in dev mode + _isVue: true + _self: Component + _renderProxy: Component + _renderContext?: Component + _watcher: Watcher | null + _watchers: Array + _computedWatchers: { [key: string]: Watcher } + _data: Record + _props: Record + _events: Record + _inactive: boolean | null + _directInactive: boolean + _isMounted: boolean + _isDestroyed: boolean + _isBeingDestroyed: boolean + _vnode?: VNode | null // self root node + _staticTrees?: Array | null // v-once cached trees + _hasHookEvent: boolean + _provided?: Record // _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, 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, val: any) => number; + _i: (arr: Array, val: any) => number // resolveFilter - _f: (id: string) => Function; + _f: (id: string) => Function // renderList - _l: (val: any, render: Function) => Array | null; + _l: (val: any, render: Function) => Array | null // renderSlot _t: ( name: string, fallback?: Array, props?: Record - ) => Array | null; + ) => Array | 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, eventKeyName?: string - ) => boolean | null; + ) => boolean | null // resolve scoped slots _u: ( scopedSlots: ScopedSlotsData, res?: Record - ) => { [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 } diff --git a/typescript/global-api.d.ts b/typescript/global-api.d.ts index d484c8a99c0..eab61b82b2a 100644 --- a/typescript/global-api.d.ts +++ b/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; - config: Config; - util: Object; + // new(options?: any): Component + (options?: any): void + cid: number + options: Record + config: Config + util: Object - extend: (options: Object) => Component; - set: (target: Object | Array, key: string | number, value: T) => T; - delete: (target: Object | Array, key: string | number) => void; - nextTick: (fn: Function, context?: Object) => void | Promise; - use: (plugin: Function | Object) => GlobalAPI; - mixin: (mixin: Object) => GlobalAPI; - compile: ( - template: string - ) => { render: Function; staticRenderFns: Array }; + extend: (options: Object) => typeof Component + set: (target: Object | Array, key: string | number, value: T) => T + delete: (target: Object | Array, key: string | number) => void + nextTick: (fn: Function, context?: Object) => void | Promise + use: (plugin: Function | Object) => GlobalAPI + mixin: (mixin: Object) => GlobalAPI + compile: (template: string) => { + render: Function + staticRenderFns: Array + } - 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: (value: T) => T; + observable: (value: T) => T // allow dynamic method registration - [key: string]: any; + [key: string]: any } diff --git a/typescript/options.d.ts b/typescript/options.d.ts index c06aa595454..b562a913235 100644 --- a/typescript/options.d.ts +++ b/typescript/options.d.ts @@ -12,6 +12,8 @@ declare type InternalComponentOptions = { type InjectKey = string | Symbol; declare type ComponentOptions = { + [key: string]: any + componentId?: string; // data