Skip to content

Commit bb7c543

Browse files
HerringtonDarkholmeyyx990803
authored andcommitted
fix vuejs#5539: improve isDef type definition (vuejs#5549)
* fix vuejs#5539: improve flow type coverage * skip unnecessary object creation * use flow internal syntax to enable predicate type
1 parent 1635ca7 commit bb7c543

File tree

9 files changed

+26
-10
lines changed

9 files changed

+26
-10
lines changed

flow/component.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ declare interface Component {
4242
$once: (event: string, fn: Function) => Component;
4343
$off: (event?: string | Array<string>, fn?: Function) => Component;
4444
$emit: (event: string, ...args: Array<mixed>) => Component;
45-
$nextTick: (fn: Function) => void;
45+
$nextTick: (fn: Function) => void | Promise<*>;
4646
$createElement: (tag?: string | Component, data?: Object, children?: VNodeChildren) => VNode;
4747

4848
// private properties

flow/global-api.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ declare interface GlobalAPI {
77
extend: (options: Object) => Function;
88
set: <T>(target: Object | Array<T>, key: string | number, value: T) => T;
99
delete: <T>(target: Object| Array<T>, key: string | number) => void;
10-
nextTick: (fn: Function, context?: Object) => void;
10+
nextTick: (fn: Function, context?: Object) => void | Promise<*>;
1111
use: (plugin: Function | Object) => void;
1212
mixin: (mixin: Object) => void;
1313
compile: (template: string) => { render: Function, staticRenderFns: Array<Function> };

src/core/observer/watcher.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import {
1212
handleError
1313
} from '../util/index'
1414

15+
import type { ISet } from '../util/index'
16+
1517
let uid = 0
1618

1719
/**
@@ -32,8 +34,8 @@ export default class Watcher {
3234
active: boolean;
3335
deps: Array<Dep>;
3436
newDeps: Array<Dep>;
35-
depIds: Set;
36-
newDepIds: Set;
37+
depIds: ISet;
38+
newDepIds: ISet;
3739
getter: Function;
3840
value: any;
3941

@@ -242,7 +244,7 @@ function traverse (val: any) {
242244
_traverse(val, seenObjects)
243245
}
244246

245-
function _traverse (val: any, seen: Set) {
247+
function _traverse (val: any, seen: ISet) {
246248
let i, keys
247249
const isA = Array.isArray(val)
248250
if ((!isA && !isObject(val)) || !Object.isExtensible(val)) {

src/core/util/debug.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
/* @flow */
2+
13
import config from '../config'
24
import { noop } from 'shared/util'
35

46
export let warn = noop
57
export let tip = noop
6-
export let formatComponentName
8+
export let formatComponentName: Function = (null: any) // work around flow check
79

810
if (process.env.NODE_ENV !== 'production') {
911
const hasConsole = typeof console !== 'undefined'

src/core/util/env.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ if (typeof Set !== 'undefined' && isNative(Set)) {
153153
_Set = Set
154154
} else {
155155
// a non-standard Set polyfill that only works with primitive keys.
156-
_Set = class Set {
156+
_Set = class Set implements ISet {
157157
set: Object;
158158
constructor () {
159159
this.set = Object.create(null)
@@ -170,4 +170,11 @@ if (typeof Set !== 'undefined' && isNative(Set)) {
170170
}
171171
}
172172

173+
interface ISet {
174+
has(key: string| number): boolean;
175+
add(key: string| number): mixed;
176+
clear(): void;
177+
}
178+
173179
export { _Set }
180+
export type { ISet }

src/core/util/error.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
/* @flow */
2+
13
import config from '../config'
24
import { warn } from './debug'
35
import { inBrowser } from './env'
46

5-
export function handleError (err, vm, info) {
7+
export function handleError (err: Error, vm: any, info: string) {
68
if (config.errorHandler) {
79
config.errorHandler.call(null, err, vm, info)
810
} else {

src/core/util/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* @flow */
2+
13
export * from 'shared/util'
24
export * from './lang'
35
export * from './env'

src/core/vdom/create-functional-component.js

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export function createFunctionalComponent (
2121
const props = {}
2222
const propOptions = Ctor.options.props
2323
if (isDef(propOptions)) {
24+
propsData = propsData || {}
2425
for (const key in propOptions) {
2526
props[key] = validateProp(key, propOptions, propsData)
2627
}

src/shared/util.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function isUndef (v: any): boolean {
66
return v === undefined || v === null
77
}
88

9-
export function isDef (v: any): boolean {
9+
export function isDef (v: any) /* : %checks */ {
1010
return v !== undefined && v !== null
1111
}
1212

@@ -103,7 +103,7 @@ export function remove (arr: Array<any>, item: any): Array<any> | void {
103103
* Check whether the object has the property.
104104
*/
105105
const hasOwnProperty = Object.prototype.hasOwnProperty
106-
export function hasOwn (obj: Object, key: string): boolean {
106+
export function hasOwn (obj: Object | Array<*>, key: string): boolean {
107107
return hasOwnProperty.call(obj, key)
108108
}
109109

0 commit comments

Comments
 (0)