Skip to content

Commit 5e1d7bc

Browse files
committed
fix(core): fix type check for Date prop
1 parent 4bcf4b0 commit 5e1d7bc

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/core/util/props.js

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
toRawType,
99
hyphenate,
1010
capitalize,
11+
isDate,
1112
isPlainObject
1213
} from 'shared/util'
1314

@@ -166,6 +167,8 @@ function assertType (value: any, type: Function, vm: ?Component): {
166167
valid = isPlainObject(value)
167168
} else if (expectedType === 'Array') {
168169
valid = Array.isArray(value)
170+
} else if (expectedType === 'Date') {
171+
valid = isDate(value)
169172
} else {
170173
try {
171174
valid = value instanceof type

src/shared/util.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ export function isRegExp (v: any): boolean {
6363
return _toString.call(v) === '[object RegExp]'
6464
}
6565

66+
export function isDate (v: any): boolean {
67+
return v instanceof Date || _toString.call(v) === '[object Date]'
68+
}
69+
6670
/**
6771
* Check if val is a valid array index.
6872
*/
@@ -294,7 +298,7 @@ export function looseEqual (a: any, b: any): boolean {
294298
return a.length === b.length && a.every((e, i) => {
295299
return looseEqual(e, b[i])
296300
})
297-
} else if (a instanceof Date && b instanceof Date) {
301+
} else if (isDate(a) && isDate(b)) {
298302
return a.getTime() === b.getTime()
299303
} else if (!isArrayA && !isArrayB) {
300304
const keysA = Object.keys(a)

0 commit comments

Comments
 (0)