In a React TypeScript project, there are 2 ways we can use Types and Interfaces.
- Create and export a type/interface in a file (e.g. FileA) and import it and use it in another file (FileB). for e.g.
// FileA.ts
export interface Foo {
foo: number;
}
//FileB.ts
import {Foo} from ./FileA;
- The other approach is we can create a declaration file for e.g.
types.d.tsand any interface/type defined in this file is automatically in the whole app and we don't have to import/export those.
The question is which approach is better and should be used? I mean does import/export have a cost attached to it like in the first one?
Thanks