How do we access an interface defined in a declaration file? Eg. I'm having issues with the redux package. Take the store declaration :
export interface Store<S> { ... }
However, in our own code we cannot type variables as Store<S>
as
$ 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:
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?
Something that's export
ed from one file must be import
ed to be consumed from another file.
Write import { Store } from 'redux';
in the file you're consuming it from to use the type locally.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.