diff --git a/flow/component.js b/flow/component.js index cce82548..e079df4f 100644 --- a/flow/component.js +++ b/flow/component.js @@ -42,7 +42,7 @@ declare interface Component { $once: (event: string, fn: Function) => Component; $off: (event?: string | Array, fn?: Function) => Component; $emit: (event: string, ...args: Array) => Component; - $nextTick: (fn: Function) => void; + $nextTick: (fn: Function) => void | Promise<*>; $createElement: (tag?: string | Component, data?: Object, children?: VNodeChildren) => VNode; // private properties diff --git a/flow/global-api.js b/flow/global-api.js index 3dff1a8e..d4cd4d4e 100644 --- a/flow/global-api.js +++ b/flow/global-api.js @@ -7,7 +7,7 @@ declare interface GlobalAPI { extend: (options: Object) => Function; set: (target: Object | Array, key: string | number, value: T) => T; delete: (target: Object| Array, key: string | number) => void; - nextTick: (fn: Function, context?: Object) => void; + nextTick: (fn: Function, context?: Object) => void | Promise<*>; use: (plugin: Function | Object) => void; mixin: (mixin: Object) => void; compile: (template: string) => { render: Function, staticRenderFns: Array }; diff --git a/src/core/observer/watcher.js b/src/core/observer/watcher.js index 213bc85c..3f3993df 100644 --- a/src/core/observer/watcher.js +++ b/src/core/observer/watcher.js @@ -12,6 +12,8 @@ import { handleError } from '../util/index' +import type { ISet } from '../util/index' + let uid = 0 /** @@ -32,8 +34,8 @@ export default class Watcher { active: boolean; deps: Array; newDeps: Array; - depIds: Set; - newDepIds: Set; + depIds: ISet; + newDepIds: ISet; getter: Function; value: any; @@ -242,7 +244,7 @@ function traverse (val: any) { _traverse(val, seenObjects) } -function _traverse (val: any, seen: Set) { +function _traverse (val: any, seen: ISet) { let i, keys const isA = Array.isArray(val) if ((!isA && !isObject(val)) || !Object.isExtensible(val)) { diff --git a/src/core/util/debug.js b/src/core/util/debug.js index d50ee221..ad19e167 100644 --- a/src/core/util/debug.js +++ b/src/core/util/debug.js @@ -1,9 +1,11 @@ +/* @flow */ + import config from '../config' import { noop } from 'shared/util' export let warn = noop export let tip = noop -export let formatComponentName +export let formatComponentName: Function = (null: any) // work around flow check if (process.env.NODE_ENV !== 'production') { const hasConsole = typeof console !== 'undefined' diff --git a/src/core/util/env.js b/src/core/util/env.js index ec5feff4..f959fb71 100644 --- a/src/core/util/env.js +++ b/src/core/util/env.js @@ -153,7 +153,7 @@ if (typeof Set !== 'undefined' && isNative(Set)) { _Set = Set } else { // a non-standard Set polyfill that only works with primitive keys. - _Set = class Set { + _Set = class Set implements ISet { set: Object; constructor () { this.set = Object.create(null) @@ -170,4 +170,11 @@ if (typeof Set !== 'undefined' && isNative(Set)) { } } +interface ISet { + has(key: string| number): boolean; + add(key: string| number): mixed; + clear(): void; +} + export { _Set } +export type { ISet } diff --git a/src/core/util/error.js b/src/core/util/error.js index 595cd323..69d44429 100644 --- a/src/core/util/error.js +++ b/src/core/util/error.js @@ -1,8 +1,10 @@ +/* @flow */ + import config from '../config' import { warn } from './debug' import { inBrowser } from './env' -export function handleError (err, vm, info) { +export function handleError (err: Error, vm: any, info: string) { if (config.errorHandler) { config.errorHandler.call(null, err, vm, info) } else { diff --git a/src/core/util/index.js b/src/core/util/index.js index 8ccff396..f88dd4eb 100644 --- a/src/core/util/index.js +++ b/src/core/util/index.js @@ -1,3 +1,5 @@ +/* @flow */ + export * from 'shared/util' export * from './lang' export * from './env' diff --git a/src/core/vdom/create-functional-component.js b/src/core/vdom/create-functional-component.js index 9ef6e72b..335c32a6 100644 --- a/src/core/vdom/create-functional-component.js +++ b/src/core/vdom/create-functional-component.js @@ -21,6 +21,7 @@ export function createFunctionalComponent ( const props = {} const propOptions = Ctor.options.props if (isDef(propOptions)) { + propsData = propsData || {} for (const key in propOptions) { props[key] = validateProp(key, propOptions, propsData) } diff --git a/src/shared/util.js b/src/shared/util.js index eceb0ac4..f7d68e60 100644 --- a/src/shared/util.js +++ b/src/shared/util.js @@ -6,7 +6,7 @@ export function isUndef (v: any): boolean { return v === undefined || v === null } -export function isDef (v: any): boolean { +export function isDef (v: any) /* : %checks */ { return v !== undefined && v !== null } @@ -103,7 +103,7 @@ export function remove (arr: Array, item: any): Array | void { * Check whether the object has the property. */ const hasOwnProperty = Object.prototype.hasOwnProperty -export function hasOwn (obj: Object, key: string): boolean { +export function hasOwn (obj: Object | Array<*>, key: string): boolean { return hasOwnProperty.call(obj, key) }