【发布时间】:2020-09-24 10:21:13
【问题描述】:
我有一个函数可以检查 currentUrl 是否与特定字符串匹配:
const checkingPage= (currentUrl: string): match<{}> | null => {
const match = matchPath(currentUrl, {
path: '/options/:optionId',
exact: true,
strict: false
})
return match
}
不知道如何指定returnmatch的类型。
目前我收到错误:
'match' 指的是一个值,但在这里被用作一个类型。ts(2749)
但是,如果我将鼠标悬停在 const match = matchPath(currentUrl... 上,它会告诉我类型是 match<{}> | null
【问题讨论】:
-
我不确定如何在返回
match的函数中定义返回类型。如果我这样做const checkingPage= (currentUrl: string): matchPath<RouteParams>它仍然抱怨说matchPath<RouteParams> refers to a value, but is being used as a type here
标签: reactjs typescript