Javascript 遇到问题';类型位置缺少类型中的以下属性…';

Javascript 遇到问题';类型位置缺少类型中的以下属性…';,javascript,typescript,Javascript,Typescript,我试图扩展,但它给了我一个错误: Type 'Location<{ modal?: boolean | undefined; }>' is missing the following properties from type 'ILocation': ancestorOrigins, host, hostname, href, and 6 more 我的问题是,如果需要我在ILocation中列出Location的所有属性,那么扩展Location有什么意义?这不是违背了继承的全部

我试图扩展,但它给了我一个错误:

Type 'Location<{ modal?: boolean | undefined; }>' is missing the following properties from type 'ILocation': ancestorOrigins, host, hostname, href, and 6 more

我的问题是,如果需要我在
ILocation
中列出
Location
的所有属性,那么扩展
Location
有什么意义?这不是违背了继承的全部目的吗?

什么位置接口?从何处?@IanKemp我正在扩展
接口位置..
typescript/lib/lib.dom.d.ts:9906
@faithfull它不是我的
位置
接口,它是typescript的。我的印象是,我可以扩展它,将它命名为
ILocation
,然后像在OP中一样定义它,其中
ILocation
的定义与
接口ILocation{state?:{modal?:boolean}}
相同,但引发错误的是
类型位置不是通用的
。如果您向我们展示
useLocation
正在做什么,我们也希望如此。我猜这就是你问题的根源。
useLocation
是钩子,不是我的钩子。
interface ILocation extends Location {
  state?: {
    modal?: boolean
  }
}

const location: ILocation = useLocation();