TypeScript is a modern programming language often preferred over JavaScript for its added type safety. In this article, I'll share the top 10 TypeS...
For further actions, you may consider blocking this person and/or reporting abuse
Loved the explanation on dependency injection!
Nice list, but this is wrong;
TypeScript is only a static type checker that checks at compile time (or rather transpilation time).
typeof
is a JavaScript feature, not a TypeScript feature. Even though javascript does not have strict static typing, every language must still have the concept of types at some point because hardware instructions are different for say string operations and numerical operations. Typescripts type system is something separate from that. It's ONLY a static checker performed before code is run, and TypeScript-specific code features will never run at runtime.The covariance example is incorrect. Who else can spot it? I see many comments on the wonders of the article, many reactions too, but nobody notices it? Hmmm. People, what's up?
sorry! I just fixed it .
Still wrong.
Enlighten us Jose
The author changed the example completely now. This new example is OK, although it is a bit longer and has unneeded functions (for the purposes of demonstrating covariance).
Awesome detailed explanation 🔥
console.log(func("True")) //Error: boolean cannot be passed as argument
is not correct. "True" is a string, but boolean is declared as acceptable in herefunction func(param:number|boolean)
. Comments lie. Am I an liar?I didn't get you
The string "true" is not a the boolean type true.
typeof("true") !== typeof(true)
I know I wanted to show that it we will get error when we pass "True" when we are only supposed to pass either string or number.
I think you refer the wrong part. I am talking about
6. Conditional Types
.Quoting:
**number **and **boolean **are allowed, but you pass a string. The comment is wrong telling a **boolean **can not be passed. Same for using
"True"
as string pretending a true boolean is very misleading and terrible wording.Ahhh!Let me fix the comment.
Thanks for reading!
@niharikaa you should fix the comment. It is "Error: string cannot be passed as argument. " Boolean is one of the optional parameters in the function. "True" is the string, it is not a boolean. true without quotes and without capital letter is a boolean
You're welcome and thanks for the article.
Thanks to your article, I was able to understand D.I
Very helpful!Thanks for the article.
Such a Great Article......Thanks for Sharing....!!!!!!
Great very useful all points.
Thanks for sharing ☺️
Great Article!
great article and great explanation too👏
Amazing article!
Thanks for sharing such a detailed blog!
Cool!
HasProperty was cool to know! But in what context I can use it?
Here's an example where I had to use it. I was using a component library in Nuxt.js for a table. It took in two paramters; data and columns. The columns parameter was a list of objects with a property
label
of type string and a propertykey
of type string. The key described which properties to read for that specific column. For example:It's a similar problem, but slightly more advanced because you need to create a recursive type as well as do some string literal types in typescripts type system (not javascript).
My brain hurts but its cool. something new to learn about typescript <3
Nice list of features and examples. The infer concept seems helpful but I still don't understand it as there wasn't an explanation, but good enough for me to lookup more on my own. Thanks for sharing!
These technics are not "advanced" because all of them just what make Typescript - Typescript. Not the first day.
Every programming language has advanced concepts that you come across as you gain more experience. These concepts are, of course, expressed in the language itself, so I'm not sure what you're trying to point out here.
Great. tnx.
something new to learn about typescript <3