-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Description
List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily and help provide feedback.
- Declare variables in uniquie line
- multiple variables of the same type
- single line variables
✅ Viability Checklist
My suggestion meets these guidelines:
- [✅] This wouldn't be a breaking change in existing TypeScript/JavaScript code
- [ ? ] This wouldn't change the runtime behavior of existing JavaScript code
- [✅] This could be implemented without emitting different JS based on the types of the expressions
- [✅] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- [✅] This feature would agree with the rest of TypeScript's Design Goals.
⭐ Suggestion
In Java, it is possible to declare multiple variables of the same type in a single line, as in String varA, varB, varC;. This can make the code more concise and easier to read, especially when declaring several variables of the same type.
I would like to propose adding similar syntax to TypeScript, allowing developers to declare multiple variables of the same type in a single line.
📃 Motivating Example
Add support for declaring multiple variables of the same type in a single line using a comma-separated syntax, as in let (varA, varB, varC): string;. This would allow developers to declare several variables of the same type more concisely and improve the readability of their code.
This feature would improve the readability and conciseness of TypeScript code, making it easier to declare multiple variables of the same type in a single line.
The suggestion of being able to declare multiple variables of the same type on a single line seems to meet several of the TypeScript design criteria:
-
Productivity: This suggestion could improve developers' productivity by allowing them to declare multiple variables of the same type in a single line and reducing the amount of code they need to write.
-
Scalability: Adding this feature could improve the scalability of the language, allowing developers to handle large projects with less code and increasing readability.
-
Compatibility: If implemented correctly, this feature should not break compatibility with previous versions of TypeScript.
-
Consistency: This suggestion could increase the consistency of the language by allowing developers to declare multiple variables of the same type uniformly.
💻 Use Cases
let (firstName, lastName, surName): string;
let (age, height, weight): number;
let (varA, varB, varC): CustomInterface[] = [];
currently:
let firstName: string, lastName: string; surName: string;
let age: number, height: number, weight: number;
let varA: CustomInterface[] = [], varB: CustomInterface[] = [], varC: CustomInterface[] = [];
Thank you so much and I hope you consider my suggestion.
Best regards.