Skip to content

Commit 1fc0952

Browse files
authored
Merge branch 'vuejs:main' into bwsy/fix/slot
2 parents 01a966d + fe77e2b commit 1fc0952

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

BACKERS.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<h1 align="center">Sponsors &amp; Backers</h1>
22

3-
Vue.js is an MIT-licensed open source project with its ongoing development made possible entirely by the support of the awesome sponsors and backers listed in this file. If you'd like to join them, please consider [ sponsor Vue's development](https://vuejs.org/sponsor/).
3+
Vue.js is an MIT-licensed open source project with its ongoing development made possible entirely by the support of the awesome sponsors and backers listed in this file. If you'd like to join them, please consider [ sponsoring Vue's development](https://vuejs.org/sponsor/).
44

55
<p align="center">
66
<a target="_blank" href="https://sponsors.vuejs.org/backers.svg">

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Please follow the documentation at [vuejs.org](https://vuejs.org/)!
66

77
## Sponsors
88

9-
Vue.js is an MIT-licensed open source project with its ongoing development made possible entirely by the support of these awesome [backers](https://github.com/vuejs/core/blob/main/BACKERS.md). If you'd like to join them, please consider [ sponsor Vue's development](https://vuejs.org/sponsor/).
9+
Vue.js is an MIT-licensed open source project with its ongoing development made possible entirely by the support of these awesome [backers](https://github.com/vuejs/core/blob/main/BACKERS.md). If you'd like to join them, please consider [ sponsoring Vue's development](https://vuejs.org/sponsor/).
1010

1111
<p align="center">
1212
<h3 align="center">Special Sponsor</h3>

packages/runtime-core/__tests__/componentProps.spec.ts

+36
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,42 @@ describe('component props', () => {
321321
expect(`Missing required prop: "num"`).toHaveBeenWarned()
322322
})
323323

324+
test('warn on type mismatch', () => {
325+
class MyClass {
326+
327+
}
328+
const Comp = {
329+
props: {
330+
bool: { type: Boolean },
331+
str: { type: String },
332+
num: { type: Number },
333+
arr: { type: Array },
334+
obj: { type: Object },
335+
cls: { type: MyClass },
336+
fn: { type: Function },
337+
},
338+
setup() {
339+
return () => null
340+
}
341+
}
342+
render(h(Comp, {
343+
bool: 'true',
344+
str: 100,
345+
num: '100',
346+
arr: {},
347+
obj: 'false',
348+
cls: {},
349+
fn: true,
350+
}), nodeOps.createElement('div'))
351+
expect(`Invalid prop: type check failed for prop "bool". Expected Boolean, got String`).toHaveBeenWarned()
352+
expect(`Invalid prop: type check failed for prop "str". Expected String with value "100", got Number with value 100.`).toHaveBeenWarned()
353+
expect(`Invalid prop: type check failed for prop "num". Expected Number with value 100, got String with value "100".`).toHaveBeenWarned()
354+
expect(`Invalid prop: type check failed for prop "arr". Expected Array, got Object`).toHaveBeenWarned()
355+
expect(`Invalid prop: type check failed for prop "obj". Expected Object, got String with value "false"`).toHaveBeenWarned()
356+
expect(`Invalid prop: type check failed for prop "fn". Expected Function, got Boolean with value true.`).toHaveBeenWarned()
357+
expect(`Invalid prop: type check failed for prop "cls". Expected MyClass, got Object`).toHaveBeenWarned()
358+
})
359+
324360
// #3495
325361
test('should not warn required props using kebab-case', async () => {
326362
const Comp = {

packages/runtime-core/src/componentProps.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -557,8 +557,8 @@ function validatePropName(key: string) {
557557
// use function string name to check type constructors
558558
// so that it works across vms / iframes.
559559
function getType(ctor: Prop<any>): string {
560-
const match = ctor && ctor.toString().match(/^\s*function (\w+)/)
561-
return match ? match[1] : ctor === null ? 'null' : ''
560+
const match = ctor && ctor.toString().match(/^\s*(function|class) (\w+)/)
561+
return match ? match[2] : ctor === null ? 'null' : ''
562562
}
563563

564564
function isSameType(a: Prop<any>, b: Prop<any>): boolean {

0 commit comments

Comments
 (0)