- 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.
- string, number, boolean
- arrays are more like to have the same type of data unless its provided with different statement for example array of numbers can't contains string if not declared.
- any type means that we this variable can be assigned to any data type because we may not know what type of data is returning, but also we should avoid using any as much as possible.
- enums is creating a predefined set of constants so don't have to redeclare of mistyping values, using enums for defining a set of values provides us a more stable way to interact with our data.
- optional chaining is a way to let us know if the requested object or entity is exist and not null because in typescript not knowing the entity which is a part of the object gives an error so in this case we use optional chaining to avoid compiling errors.
- dynamically typed is when a variables takes the type depends on the assigned value and can be changed with redeclaration, but in typescript where its statically typed language/environment it let us choose the type of the variables before assigning the value which makes out variable more controllable.
- interface is basically the predefined structure for our data that will be held inside our class, so our class will work fine as long as it followed our interface.
- these are more like an advanced type for saving data intersection basically meaning that we can have both numbers or strings at the same time but union is about having just one type at a time and can be used by the operator '|'.
- nice question :)) as long as its not required from the company we dont wanna use it gl;fdkgjdf. :DD
- 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.
@yaman3bd
@edaguler00
@Ibraheem