You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In all programming languages, "const" means "a design time constant" which is immutable. But not for JavaScript, it is a variable that is a readonly within context. It is a "readonly" - not a constant.
Type script should easily "fix" this allowing us to use "readonly" for variable declaration.
Wrong:
(a: number) => {
const b: number = a || 1; // this is not a constant, this is readonly variable
}
Good:
(a: number) => {
readonly b: number = a || 1; // this makes sense
}
And transpiler should be able to easily just rename from "readonly b" to "const b" in JavaScript version of the code.
I as a developer with knowledge of other programming languages have so much issue with abuse of "const" keyword in JavaScript => and TypeScript, yet again has an opportunity to fix broken language.
Pretty please?
Thank you!
The text was updated successfully, but these errors were encountered:
Ok, that is 30 minutes of video, if you had time to record it, I will find time to watch it in full, thank you.
In general, I understand your point.
But isn't a "readonly" for class property a syntactic sugar added by TypeScript, adding more than just plain strict typings? Seams that adding support for "readonly" variables is kinda next natural step forward?
TheCelavi
changed the title
[ FEATURE REQUEST ] TypeScript should fix broken "const" variable declaration in JavaScript
[ FEATURE REQUEST ] TypeScript could fix broken "const" variable declaration in JavaScript
Aug 12, 2021
In all programming languages, "const" means "a design time constant" which is immutable. But not for JavaScript, it is a variable that is a readonly within context. It is a "readonly" - not a constant.
Type script should easily "fix" this allowing us to use "readonly" for variable declaration.
Wrong:
And transpiler should be able to easily just rename from "readonly b" to "const b" in JavaScript version of the code.
I as a developer with knowledge of other programming languages have so much issue with abuse of "const" keyword in JavaScript => and TypeScript, yet again has an opportunity to fix broken language.
Pretty please?
Thank you!
The text was updated successfully, but these errors were encountered: