Typically, I would recommend organizing interfaces and types based on the context they are used in. For example, your login.ts
file, which contains all the login logic, should also export any related types (such as LoginApiResponse
). If you have multiple files with nested concerns structures (like login.ts
, accessTokenLogin.ts
, twoFactorAuth
...), where login.ts
is the main module bringing everything together, it's a good idea to re-export all interfaces declared in sub-modules there as well. This way, you would have:
login.ts
export interface GeneralLoginInterface {
prop: string
}
export { Response } from "./twoFactorAuth.ts"
And only import from login.ts
(note: this can be extended to actual code like classes and functions as well).
If members of your sub-modules have conflicting names (for example, if both twoFactorAuth.ts
and accessTokenLogin.ts
have a type named Response), consider exporting them under different namespaces as explained here.
Keep in mind that this is just a suggestion; you have the flexibility to import types wherever needed and not worry about circular dependencies since types are stripped away at runtime.