【发布时间】:2020-06-08 17:51:01
【问题描述】:
我有这个代码:
const assetsRedirection = (props: AssetsProps): null => {
const query = queryString.parse(props.location.search);
const url = query.url;
if (url) {
window.location.href = url;
}
return null;
};
我收到了这个错误:
Type 'string | string[]' is not assignable to type 'string'.
Type 'string[]' is not assignable to type 'string'.ts(2322)
这来自window.location.href = url;这一行,正好在window.location.href。
我怎样才能摆脱它?
【问题讨论】:
-
嗨,@jonrsharpe 你能详细说明一下吗?
-
我添加了文档链接。
-
@jonrsharpe 成功了。我做了
window.location.href = url as string;。如果你回答我可以给你一个很酷的绿色检查。
标签: javascript reactjs typescript ecmascript-6