3 ms·
Typescripts goal is to allow using existing JavaScript idioms while gaining the advantages of static type checking. I don't think it's too bonkers for the type
by adrusi 8y ago
Typescripts goal is to allow using existing JavaScript idioms while gaining the advantages of static type checking.
I don't think it's too bonkers for the type of a variable to change within the same scope, as long as there's some clear delineation. In rust you can redeclare a variable with the same name but different type:
let x: i32 = 99;
println!("{}", x);
let x: &str = "shadows";
println!("{}", x);
Kotlin does something very similar to typescript for null checks: https://kotlinlang.org/docs/reference/null-safety.html https://kotlinlang.org/docs/reference/null-safety.html
I don't know what's so crazy about a variable's type changing within the same scope except that languages from before 2010 mostly didn't allow that.
- steveklabnik 8y agoTo be clear, this doesn’t change the type in Rust. It creates a new variable with the same name. Very different thing!