I've received the aforementioned error when making the following TypeScript code. The problem is obviously that the urls, type and sub properties don't exist on a parameter of the string[] type, but they would not be read if that was the type of the targeted parameter. I'm extremely new to TypeScript, this is my first attempt working with it, so I'm probably missing something relatively basic.
interface targeterInterface {
urls: string | string[];
type?: string;
sub?: string;
}
function exp(targeter: string | targeterInterface | string[]) {
let target: string[] | string;
let type: string;
let sub: string;
if (typeof targeter === "object") {
target = targeter.urls;
type = targeter.type;
sub = targeter.sub;
} else if (typeof targeter === "string") {
target = targeter;
} else {
console.log("It's an array!");
}
}
Thanks for any help!