Question: Seeking feedback on the preferred import/export/usage system in TypeScript. While direct imports (#1) are common, which approach is considered best practice in well-established production codebases?
Context: Having worked on large-scale projects in TypeScript and Go, I have primarily used approach #1 but am exploring package-based imports more recently. TypeScript typically favors direct imports, whereas Go leans towards packages. Personally, I lean towards the package approach (#2a or #2b), but I'm curious about the general consensus on whether direct imports (#1) are superior. Any insights on the recommended practice for scalability would be appreciated. ** Direct Import Example:**
File: /services/aws/api-gateway/createAPIGateway.ts
Function Name: createAPIGateway()
Index.ts:
import createAPIGateway from './createAPIGateway';
export { createAPIGateway };
Usage:
import { createAPIGateway } from './services/aws/api-gateway/index';
createAPIGateway();
2a. Package Import Example 1:
File: /services/aws/api-gatewaycreateAPIGateway.ts
Function Name: createAPIGateway()
Index.ts:
import createAPIGateway from './createAPIGateway';
export const apigateway = { createAPIGateway }
Usage:
import { apigateway } from './services/aws/api-gateway/index';
apigateway.createAPIGateway();
2b. Package Import Example 2:
File: /services/aws/api-gateway/create.ts
Function Name: create()
Index.ts:
import create from './create';
export const apigateway = { create }
Usage:
import { apigateway } from './services/aws/api-gateway/index';
apigateway.create();
This inquiry pertains to industry best practices.