Pelle Jacobs Pelle Jacobs - 1 year ago 121
TypeScript Question

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. Take the store declaration:

export interface Store<S> { ... }

However, in our own code we cannot type variables 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
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

Answer Source

Something that's exported from one file must be imported to be consumed from another file.

Write import { Store } from 'redux'; in the file you're consuming it from to use the type locally.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download