Pelle Jacobs
Pelle Jacobs

Reputation: 2589

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 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?

Upvotes: 0

Views: 110

Answers (1)

Ryan Cavanaugh
Ryan Cavanaugh

Reputation: 221044

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.

Upvotes: 1

Related Questions