I am having an issue with destructuring and types. I have a custom type and a function that returns that type:
interface CustomNameInfo {
name: string;
access: string
}
async getNameInfo(): Promise<CustomNameInfo> {
//logic
return {
name: "FOO",
access: "none"
}
}
if I use approach 1, I get no type errors:
let name, access, resp;
if (!hasName) {
resp = await this.getNameInfo();
access = resp.access;
name = resp.name;
}
If I use the approach I am trying to use though with destructuring, I am getting the TS error: Property 'access' and
namedoes not exist on type
CustomNameInfo``
let name, access;
if (!hasName) {
({ name, access } = await this.getNameInfo());
}