Encountering a TypeScript error with the following code:
if (this.$route?.query?.domainName) {
this.setDomain(this.$route.query.domainName);
}
The code snippet above is causing the following error message:
TypeScript - Argument of type 'string | (string | null)[]' is not assignable to parameter of type 'string'
if (this.$route?.query?.domainName) {
this.setDomain(this.$route.query.domainName);
^
}
The setDomain function specifically expects a parameter of type string:
setDomain(domain: string) {
this.domainName = domain;
}
It is puzzling why the parameter could potentially be null when I have validated the existence of the object property using the optional chaining operator (?). What could be causing this error?