- What are the primitive types in TypeScript?
- Explain how the arrays work in TypeScript.
- What is
any
type, and should we use it? - How does
enums
work and how are they usefull? - What is optional chaining and how does it work?
- "Javascript is dynamically typed" what does that mean? and how does Typescript affect that?
- What is the difference between Interface and Class?
- What is union and intersection type?
- Why to even bother with Typescript???
-
-
Save halitbatur/74b60dbb7682893b211f3ad9329f84a6 to your computer and use it in GitHub Desktop.
- number , string , boolean , bigint , symbol , undefined , and null
- Array is a special type of data type which can store multiple values of different data types sequentially using a special syntax,
let fruits: string[] = ['Apple', 'Orange', 'Banana'] - any is like not specifying a type basically just like what we do in JS. we should try to avoid using it.
- Enums allow a developer to define a set of named constants. Using enums can make it easier to document intent, or create a set of distinct cases.
- optional chaining lets us write code where TypeScript can immediately stop running some expressions if we run into a null or undefined
- it means that type checks are performed mostly at run time, JavaScript is a dynamically typed language, but TypeScript is a statically typed language.
- A class describes the attributes and behaviors of an object.
An interface contains behaviors that a class implements. - Union for example is used for either a number or a string combining, but intersection allows you to add existing types to get a single type that has all the features you need.
- more reliable because of The strict typing.
@eniz @elif
1- TypeScript supports 7 primitive types number , string , boolean , bigint , symbol , undefined , and null
2- TypeScript supports arrays, similar to JavaScript. Also arrays in TypeScript are similar to arrays to arrays in other languages. There are two ways to declare an array:
1.using square brackets
let fruits: string[] = ['Apple', 'Orange', 'Banana'];
2.using generic array types
let fruits: Array = ['Apple', 'Orange', 'Banana'];
Array has common following features:
-Stored sequentially in memory(easier to access elements by index)
-Contains elements of the same type
-Size of array can not be changed after arrays is declare
3- It allows us to assign “any” particular value to that value.We should be using it when we don’t really know what the type of the return value is. For example, you are using a third party library and there is no type definition for a value, then you should use any.
4- Enums are a feature in TypeScript that makes it easier to handle named sets of constants. By default an enum is number based, starting at zero, and each option is assigned an increment by one. This is useful when the value is not important.
5- The optional changing operator (?.) enables you to read the value of a property located deep within a chain of connected objects without having to check that each reference in the chain is valid, and it returns undefined when it reads the first property of an undefined variable in the chain
6- A language is dynamically typed when the type of a variable is checked in the run time. While in a statically typed language all checks will be performed during compile/build run before we actually execute our program.
Typescript is a superset of JavaScript but they are not really the same. While JavaScript is dynamically typed, Typescript is statically typed language.
7-A class describes the attributes and behaviors of an object while an interface contains behaviors that a class implements.
8- An intersection type combines multiple types into one. A union type describes a value that can be one of several types
9- a) You can avoid masterfully-hidden-ninja errors like the classic “ 'undefined' is not a function”.
b) It is easier to refactor code without breaking it significantly.
c) Orienting oneself in complex, large-scale systems is not a nightmare anymore.
@emirsagit @algiknr