Looks like there should be a special case for var. The following code,
describe('.constructor', () => {
var a = new Quaternion()
checkQuaternion(a, 0, 0, 0, 1)
var a = new Quaternion(x, y, z, w)
checkQuaternion(a, x, y, z, w)
})
gives the error
ERROR TS2300: Duplicate identifier 'a'.
var a = new Quaternion(x, y, z, w)
~
in src/as/glas/math/Quaternion.spec.ts(138,6)
Perhaps AS should treat the second var as just a = new Quaternion(x, y, z, w) as if it didn't have the var in front of it, so that it behaves like what people expect in JS? I don't imagine this changes the underlying compiler output.
Shadow variable declaration is bad practice even for different scopes, but in same scope this definitely may lead to hidden issues and errors. So just remove var for second statement
I agree, and I don't write code that way (I copied this code while porting it to AS). Of course I modified it to work.
But nonetheless, I think it may be nice match TS/JS a little more closely where possible, the goal being to "transpile TypeScript to Wasm"
Someone else could argue that enforcing proper var placement, which a linter would do otherwise, fits well with a strict subset because it prevents mixing types and other mistakes. Overall I don't have a strong opinion on this one, so maybe let's see what others think as well.
I agree that the current way is actually better, behaving like let, which is why let was introduced anyway.
Personally I vote for ban var at all and leave only let and const
Haha. Well, that'd be nice too! Question is, how true to TypeScript do you want to be?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
Personally I vote for ban
varat all and leave onlyletandconst