When using VueJS with TypeScript, trying to access a property or method using this.$parent.somePropOrMethod
or this.$root.somePropOrMethod
can lead to a type error stating that
Property somePropOrMethod does not exist on type 'Vue'
The defined interface for Vue
is as follows:
export interface Vue {
...
readonly $parent: Vue;
readonly $root: Vue;
...
}
This raises the question of how one should go about accessing properties and methods on parent or root elements in a way that maintains type safety.
It appears like the interface should be Vue & {[key: string]: any}
in order to permit unknown properties and methods within the $root
and $parent
attributes.