I have the following file directory:
├── UseCases
| ├── SistemParamsUseCases
| | ├── getAll. ts
| | ├── getParam. ts
| | ├── SistemParamsUseCases. ts
Inside getAll.ts and getParam.ts I have the export of a function with the name of the respective file and I would like to export the two functions through SistemParamsUseCases.ts to use as follows in other files:
SistemParamsUseCases.getAll()
But I wouldn’t like to have to import using the “import * as SistemParamsUseCases from ‘…'” syntax, because this has to be done manually in all files where I’m going to use it and I would like a way where vscode import automatically.
One solution I had was, within SistemParamsUseCases.ts, I export an object containing the functions of the other files.
export const SistemParamsUseCases = { getAll, getParam};
And this works well, but when opening the functions that are being called I fall back on the object reference and not the function itself, this gets in the way of finding the function and possibly renaming it, as it would change the value of the object, but not the key.
Another solution I found was to create a new file, called export.ts where within it I just centralize the function exports:
export { getAll } from "./getAll";
export { getParam } from "./getParam";
And in SistemParamsUseCases.ts I export it with the desired name:
export * as SistemParamsUseCases from './export'
This way it maintains the individual reference of each function in the import
However, to do this I had to create an additional file for export, which was not very practical when applying to other use cases and I would like to know if there is another way to achieve the same result.
user24698510 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.