Is there a way to declare a Prop using vue-property-decorator in a class-based component without the need to initialize it?
Currently, I'm facing a dilemma:
- If I don't provide an initializer, TypeScript throws an error during compilation:
"TS2564 (TS) Property 'parentData' has no initializer and is not definitely assigned in the constructor."
- On the other hand, if I do initialize the property, VueJS issues a warning at runtime:
"Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders."
The current solution works, but dealing with the warning is bothersome and leaves me wondering if there's a better approach:
import Vue from 'vue';
import { Component, Prop } from 'vue-property-decorator';
import { Client } from '../../../../domainmodels/client';
@Component({})
export default class SearchLocationsComponent extends Vue {
@Prop()
parentData: Client = new Client();
}
My dependencies:
"devDependencies": {
"@types/webpack-env": "^1.13.0",
"aspnet-webpack": "^2.0.1",
"awesome-typescript-loader": "^3.0.0",
"css-loader": "^0.25.0",
"event-source-polyfill": "^0.0.7",
"extract-text-webpack-plugin": "^2.0.0-rc",
"file-loader": "^0.9.0",
"style-loader": "^0.13.1",
"typescript": "^2.2.1",
"url-loader": "^0.5.7",
"vue": "^2.2.2",
"vue-loader": "^11.1.4",
"vue-property-decorator": "^5.0.1",
"vue-router": "^2.3.0",
"vue-template-compiler": "^2.2.2",
"webpack": "^2.2.0",
"webpack-cli": "^3.3.2",
"webpack-hot-middleware": "^2.12.2"
}