New to Typescript. I can see that you can define an interface and use it throughout a Typescript project. And I can see many blogs and tutorials and documentation describing how you can "export" an interface. However, I don't understand why you would ever do this. I can understand of course exporting classes or constants or variables.... but what benefit ever accrues from exporting an interface? It seems like you can always use it by reference if necessary?
Clearly I am missing a key concept, and any clarity or insight offered is much appreciated.
It seems like you can always use it by reference if necessary?
Global interfaces are accessible everywhere. For making global interfaces, just put the code in a TypeScript file without top level import
and export
keywords.
But, like the old fashion global variables, global interfaces suffer from naming conflicts. Exported interfaces solve the issue.
Example:
// a.ts
export interface A {}
export default let a: A;
// b.ts
import b, {A as B} from './a'
// Here, the name of A is B