Is there any way to have private types in typescript for only a folder and its subfolders? - Stack Overflow

admin2025-04-17  4

I am building a software that has many possible api providers and one common core interface.

I want to hide the private types and use them only across a specific folder (provider) and its subfolders but not have these exported out.

Example with a provider called Super

/data/providers/super/types.ts types here to be used only within /data/providers/super/Super.ts|otherhelper.ts etc

but not to be able to import at higher levels because somewhere at /data/providers/types.ts I want to declare only the types to be used by other higher folders and logics.

I know one solution is to declare the types for example on top of /data/providers/super/Super.ts

type SuperApiResponse = {}; // some type here
// implement axio calls and responses functions class etc

This makes the types private but the file will be huge and also in typescript can't declare the types in the bottom of the file without lint error.

Any thoughts?

I know from dart for example that you could use .part.dart system to split one file into more and achieve a similar idea

转载请注明原文地址:http://anycun.com/QandA/1744861911a88664.html