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 named imports in transformed code #601

Closed
1 task
trivikr opened this issue Oct 13, 2023 · 2 comments · Fixed by #603
Closed
1 task

[Feature]: Use named imports in transformed code #601

trivikr opened this issue Oct 13, 2023 · 2 comments · Fixed by #603
Labels
enhancement New feature or request

Comments

@trivikr
Copy link
Member

trivikr commented Oct 13, 2023

Self-service

  • I'd be willing to implement this feature

Problem

If the input code contains only client initialization, the codemod uses named imports as follows:

Example input:

import AWS from "aws-sdk";
const client = new AWS.DynamoDB({ region: "us-west-2" });

Example output:

import { DynamoDB } from "@aws-sdk/client-dynamodb";
const client = new DynamoDB({ region: "us-west-2" });

However, if the input contains types, the codemod uses global import as follows:

Example input:

import AWS from "aws-sdk";
const input: AWS.DynamoDB.ListTablesInput = { Limit: 10 };

Example output:

import * as AWS_DynamoDB from "@aws-sdk/client-dynamodb";
const input: AWS_DynamoDB.ListTablesCommandInput = { Limit: 10 };

This has been done to avoid additional imports in the past, but the solution is not clean.
The users who ran codemod had requested cleaner solution in the past, like #593

Solution

Use named imports for types as follows:

Example input:

import AWS from "aws-sdk";
const input: AWS.DynamoDB.ListTablesInput = { Limit: 10 };

Example output:

import { ListTablesCommandInput } from "@aws-sdk/client-dynamodb";
const input: ListTablesCommandInput = { Limit: 10 };

Alternatives

Pass an option to the codemod to enable named import, similar to #589
This will not be straightforward to implement, and users might not discover it.

Additional context

No response

@trivikr trivikr added the enhancement New feature or request label Oct 13, 2023
@trivikr
Copy link
Member Author

trivikr commented Oct 16, 2023

The global import was introduced in the past to have as less changes in the code as possible. But as users have used the codemod, they prefer named imports.

Since import equals does not support named imports, that would be an exception to the standard.

Copy link
Contributor

github-actions bot commented Nov 1, 2023

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 Nov 1, 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
Development

Successfully merging a pull request may close this issue.

1 participant