我收到此错误
Type MyInterface' is not assignable to type 'string'
。我明白了,但想不出好的解决办法。 MyInterface
仅返回一项,即字符串。这是运行的代码。
export interface MyInterface {
pulledCoolData: string;
}
const getData = async (passedData: string): Promise<MyInterface> => {
const coolData = await getDataFromAPI(passedData);
return coolData;
};
getData(data.myData).then(response => {
window.location.href = response;//the error is on this line because reponse is type MyInterface and it is expecting a string to be passed
});
我想你忘了从
pulledCoolData
获取 MyInterface
:
getData(data.myData).then(response => {
window.location.href = response.pulledCoolData;
});
不过,我没有 TypeScript 经验,所以这可能是不正确的。