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
But this requires to remove default keyword from all these files which is ok since default keyword is not really that useful.
3) comparison operators, in ConfigurationDependentGunController.ts, SyntaxHighlightingGunController.ts
I see you use == and != comparison operators which coerce/convert types (if operands are of different type then one of them will be coerced to type of the other so they can be compared). If that is what you wanted to do then ok, but be aware of this behaviour. Alternative is to use comparison operators which don't coerce/convert types: === and !==. Type coercion also happens when doing other stuff (if (x), a + b, ...).
Examples:
[]==true// -> this will evaluate to false because empty list ([]) is coerced into false[1]==true// -> this will evaluate to true because non-empty list ([1]) is coerced into true[]===true// -> this will evaluate to false because operands are of different types[1]===true// -> this will evaluate to false because operands are of different types
Using non-coercive comparison operators is considered good practice in JavaScript/TypeScript world.
4) var keyword, in ConfigurationDependentGunController.ts, demo.ts, index.ts
Keywords var, let and const introduce variable/value bindings, let and const are perfectly fine but var has some serious issues and it should never be used as far as I am concerned.
Variables introduced by let and const are scoped to the nearest {} block, variables introduced by var are scoped to the nearest function body.
Example:
functionlousyVar(){varx="var";{varx="same var here";console.log(x);// prints "same var here"}console.log(x);// prints "same var here" -> did we really wanted to change outer variable?}functionniceLet(){letx="let";{letx="totally different variable";console.log(x);// prints "totally different variable"}console.log(x);// prints "let" -> outer variable with same name is preserved}
Everything else seems fine.
The text was updated successfully, but these errors were encountered:
@srhitect Thanks a lot for the review and all the suggestions! I learned a lot out of them and I am looking forward putting all those hints in practice in my future TypeScript coding!
Code review - TypeScript (everything mentioned here also applies to JavaScript) stuff
1) extension.ts
No need to create anonymous class and immediately instantiate it if you can create object on the spot, moreover it's not idiomatic:
Type of the host object that typescript will infer:
2) AllGunControllers.ts, exports/imports
Instead of:
You can short it like this:
Or you can do it even shorter with:
But this requires to remove
default
keyword from all these files which is ok sincedefault
keyword is not really that useful.3) comparison operators, in ConfigurationDependentGunController.ts, SyntaxHighlightingGunController.ts
I see you use
==
and!=
comparison operators which coerce/convert types (if operands are of different type then one of them will be coerced to type of the other so they can be compared). If that is what you wanted to do then ok, but be aware of this behaviour. Alternative is to use comparison operators which don't coerce/convert types:===
and!==
. Type coercion also happens when doing other stuff (if (x), a + b, ...).Examples:
Using non-coercive comparison operators is considered good practice in JavaScript/TypeScript world.
4)
var
keyword, in ConfigurationDependentGunController.ts, demo.ts, index.tsKeywords
var
,let
andconst
introduce variable/value bindings,let
andconst
are perfectly fine butvar
has some serious issues and it should never be used as far as I am concerned.Variables introduced by
let
andconst
are scoped to the nearest{}
block, variables introduced byvar
are scoped to the nearest function body.Example:
Everything else seems fine.
The text was updated successfully, but these errors were encountered: