简体   繁体   English

从声明文件访问导出的Typescript接口

[英]Access exported Typescript interfaces from declaration file

How do we access an interface defined in a declaration file? 我们如何访问声明文件中定义的接口? Eg. 例如。 I'm having issues with the redux package. 我在redux软件包中遇到问题。 Take the store declaration : 商店申报单

export interface Store<S> { ... } 

However, in our own code we cannot type variables as Store<S> as 但是,在我们自己的代码中,我们不能将变量作为Store<S>键入为

$ error TS2304: Cannot find name 'Store'.

Eg. 例如。 in: 在:

const addUser = (store: Store<number>) => {
  store.dispatch({type: "INCREMENT_USER_COUNT"})
}

But then, if we remove the export from the declaration file, the typing works fine: 但是然后,如果我们从声明文件中删除export ,则输入可以正常工作:

interface Store<S> { ... } 

Is there any way for me to actually use this interface as it is defined in the redux declaration file, without having to redefine the Store interface? 我有什么办法可以实际使用redux声明文件中定义的此接口,而不必重新定义Store接口?

Something that's export ed from one file must be import ed to be consumed from another file. 从一个文件export必须被import才能从另一个文件使用。

Write import { Store } from 'redux'; import { Store } from 'redux';写入import { Store } from 'redux'; in the file you're consuming it from to use the type locally. 在您使用它的文件中,以在本地使用该类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM