Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Use default imports to minimize identifier conflicts with existing code #239

Closed
1 task done
trivikr opened this issue Dec 29, 2022 · 3 comments · Fixed by #276
Closed
1 task done

[Feature]: Use default imports to minimize identifier conflicts with existing code #239

trivikr opened this issue Dec 29, 2022 · 3 comments · Fixed by #276
Labels
enhancement New feature or request

Comments

@trivikr
Copy link
Member

trivikr commented Dec 29, 2022

Self-service

  • I'd be willing to implement this feature

Input code

Input:

import DynamoDB from "aws-sdk/clients/dynamodb";

const ddbClient = new DynamoDB({ region: "us-west-2" });
const listTablesInput: DynamoDB.ListTablesInput = { Limit: 10 };
const listTablesOutput: DynamoDB.ListTablesOutput = await ddbClient
  .listTables(listTablesInput)
  .promise();

Existing output:

import { DynamoDB, ListTablesCommandInput, ListTablesCommandOutput } from "@aws-sdk/client-dynamodb";

const ddbClient = new DynamoDB({ region: "us-west-2" });
const listTablesInput: ListTablesCommandInput = { Limit: 10 };
const listTablesOutput: ListTablesCommandOutput = await ddbClient
  .listTables(listTablesInput);

Expected Output

import * as DynamoDB from "@aws-sdk/client-dynamodb";

const ddbClient = new DynamoDB.DynamoDB({ region: "us-west-2" });
const listTablesInput: DynamoDB.ListTablesCommandInput = { Limit: 10 };
const listTablesOutput: DynamoDB.ListTablesCommandOutput = await ddbClient.listTables(
  listTablesInput
);

Additional context

This solution not only minimizes imports which can conflict with other variables defined in the code, but also adds support for nested type definitions requested in #225

@trivikr trivikr added the enhancement New feature or request label Dec 29, 2022
@trivikr trivikr changed the title [Feature]: Use star imports to minimize imports which can conflict with existing code [Feature]: Use star imports to minimize identifier conflicts with existing code Dec 29, 2022
@trivikr
Copy link
Member Author

trivikr commented Dec 29, 2022

An attempt of implementation was made in #240

An easier solution would be to use named import for client creation and other direct uses of Identifier (like instanceof checks), and default import for TSQualified names.

import AWS_DynamoDB, { DynamoDB } from "@aws-sdk/client-dynamodb";

const ddbClient = new DynamoDB({ region: "us-west-2" });
const listTablesInput: AWS_DynamoDB.ListTablesCommandInput = { Limit: 10 };
const listTablesOutput: AWS_DynamoDB.ListTablesCommandOutput = await ddbClient.listTables(
  listTablesInput
);

@trivikr
Copy link
Member Author

trivikr commented Dec 29, 2022

An easier solution would be to use named import for client creation and other direct uses of Identifier (like instanceof checks), and default import for TSQualified names.

During internal discussions, we decided to go ahead with this suggestion.

@trivikr trivikr changed the title [Feature]: Use star imports to minimize identifier conflicts with existing code [Feature]: Use default imports to minimize identifier conflicts with existing code Dec 30, 2022
@github-actions
Copy link
Contributor

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
1 participant