Skip to content

VueTypes.extends is broken #54

@micha-vb

Description

@micha-vb

Hi,

either the extends feature is broken or I don't get it right. The following vue-component demonstrates my issue:

<template>
	<div>
		<a :href="link.url">{{ link.text }}</a>
		<a :href="linkAlt.url">{{ linkAlt.text }}</a>
	</div>
</template>

<script>
import VueTypes from 'vue-types'

const VueTypeLink = VueTypes.shape({
	text: VueTypes.string.isRequired,
	url: VueTypes.string.isRequired,
})

VueTypes.extend({
	name: 'link',
	getter: true,
	type: Object,
	validator: (v) => VueTypes.utils.validate(v, VueTypeLink),
})

console.log('VueTypes', VueTypes);

export default {
	name: 'SomeComponent',
	props: {
		link: VueTypes.link,
		linkAlt: VueTypes.link,
	}
}
</script>

Am I doing something wrong here or should that work? I'm getting the following error:

Uncaught TypeError: Cannot redefine property: isRequired
    at Function.defineProperty (<anonymous>)
    at withRequired (utils.js?732b:109)
    at toType (utils.js?732b:151)
    at Object.get [as link] (index.js?5397:85)
    at eval (Teaser.vue?715f:26)

If I remove the link and linkAlt items from the prop-object (no prop-validation is done) the console.log will output the VueTypes-Object with a "link"-object on it (as expected). That link object seems to be similar to all the default types on VueTypes (string, number etc.). So far, so good.

But as soon as I add only one type-check (just the "link"-prop) back to the prop-object, that link-object on VueTypes-console-output becomes that error message. The app itself will throw no error yet. So it seems, that the type-check works one time and only after that, the link-object becomes the error-message.

Because when I then add the second prop (linkAlt) to the props-object, the error is thrown in the console.

Thanks

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions