-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Add feature to re-declare variable #37771
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
Comments
I guess my question is what happens if two variables did this?
|
@DanielRosenwasser
|
Came here for a mildly different reason, closer related to issue #14306, some variables were "declared" in the global scope, but I chose to explicitly make them into variables. ex: const { Map } = self;
const func = () => {
const variable = new Map{...};
// Map cannot be overrode via devtools or such
} Someone I was working with had actually noticed that global lookups were slowing down their code, so I tried to test this, but TS didn't like it. |
cross-linking to #4062 |
I have a "header" type of interface:
I want to have extended interface:
if there is no inex type in
It will allow for elegant and typesafe solution. We can easily mimic this behavior with
but this results in unnecessary JS code emitted and ran |
Search Terms
redeclare variable, re-declare variable, augment variable, merge variable declaration, declaration override
Suggestion
define a
redeclare
keyword which allows re-declaration of a typed variable.e.g.
Use Cases
When an external library declares a variable, e.g.
The
redeclare
keyword can be used somewhere else to override the declaration:or augment it:
This would allow to type the pure JavaScript case of:
Examples
to extend the variable with additional static methods to
URLSearchParams
is not possible currently (see here).The feature can be used in the following way:
Checklist
My suggestion meets these guidelines:
The text was updated successfully, but these errors were encountered: