interface ExampleType {
[key: string]: string | (() => string);
}
const testObj: ExampleType = {
firstName: "Peter",
lastName: "Parker",
gender: "male",
getFullName: () => "I am Peter Parker",
};
const { firstName, lastName, getFullName } = testObj;
console.log(getFullName()); // this does not works
if (typeof getFullName === "function") {
console.log(getFullName()) // this works
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:**此表达式不可调用。并非所有类型为 'string | 的成分| (() => string)' 是可调用的。'string' 类型没有调用签名。**