DEV Community

wshi9124
wshi9124

Posted on • Updated on

Intro to TypeScript Part 2

Classes in TypeScript - TypeScript supports access modifiers (private, public and protected) (it will be public by default) In this example, we do not access to firstName and lastName because they are private only to the class, User.
readonly- makes a property as read-only(value cannot change once it is set).
Interface- In the interface, UserInterface, TypeScript expects the function getFullname in class User or their will also be an error.
Static property- only accessible on the class itself and not the instance
Image description
Generics, interfaces, and functions in TypeScript
Generics- all generic datatypes are written inside <> (instead of using any, you use generics) Instead of using multiple interfaces, we used generics (allows use to provide different data types)
Interfaces- set rules and syntax that any entity must adhere to.
Image description
Enums(enumerable) in TypeScript
Enum is the reserved word to create enumerable (should be all capitalized)
*values should be assigned with an equal sign instead of a : *Image description
Next blog: Typescript in React
Reference:
TypeScript official documentation:
https://www.typescriptlang.org/docs/handbook/intro.html
https://www.youtube.com/watch?v=gp5H0Vw39yw&ab_channel=freeCodeCamp.org

Top comments (0)