Skip to content

I have created this repository to gain knowledge about Typescript. Also, I have not worked with typescript on a practical level. So, this will be a nice way to get used to it so that I can work on my React projects.

License

Notifications You must be signed in to change notification settings

iamsomraj/Learning-Typescript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Learning Typescript

I have created this repository to gain knowledge about Typescript. Also, I have not worked with typescript on a practical level. So, this will be a nice way to get used to it so that I can work on my React projects.

Useful points

  1. Type is an easy way to refer to all the properties and methods that a value has. In TS, every value has a type. Used by TS compiler to analyse the code for errors.

  2. Type Annotation - We write code to tell TS what type of value a variable will refer to. Here, developers tell the compiler.

  3. Type Inference - Here, TS will try to guess the type of value that a variable is holding. But, in this case, TS compiler tries to infer.

  4. If we are going to write variable declaration and initialization in the same line, then we don't require types. Here, typescript will determine the type automatically. But if we just declare the variable, then TS will assign the type : any to it.

  5. Three cases to use Type Annotations:

  • When function returns any type
  • When declaration and initialization of variable happens on different lines
  • When type of variable cannot be inferred
  1. Type annotations and inference for functions:

Type inference do not work with the arguements of functions. We have to type annotate arguements. Type inference do work for the return of functions. But, we do not use it.

const add = (a: number, b: number): number => a + b;
  1. Typed Arrays - In TS, we store same type of elements in the array.

  2. Tuples - Array like structure containing only values of the properties.

  3. Type Alias - We can declare one variable as type and then assign the type. In this way, we can use the type at many places.

  4. In TS, we have to create functions that takes arguements with typed interfaces. In this way, objects will have to implement the interface in order to get executed by the function.

  5. Class:

  • By default, fields and methods have public modifiers.
  • Three modifiers: public, protected, private
  • We can not restrict the access in the child class. If we want, then we have to do it from the parent class itself.
  • By using private, we make sure that other developers cannot invoke those methods.

Content

  1. Fetchjson - Used TS for fetching data from a fake API ( you know which one ) :P

Objectives

  1. To learn about the syntax of Typescript
  2. Used ts-nodes package for compiling TS and using Node, both at the same time

Developer

LinkedIn : iamsomraj 😊

HackerRank: iamsomraj 😊

Portfolio: Somraj Mukherjee 😊

Google Play Store: Somraj Mukherjee 😊

Show Your Support

Give me a star ⭐

if this project helped you 👦 👧

Contributing

Pull requests are welcome. 🤝 For major changes, please open an issue first to discuss what you would like to change. 🙏

Please make sure to update tests as appropriate. ✌

License

MIT 📰

About

I have created this repository to gain knowledge about Typescript. Also, I have not worked with typescript on a practical level. So, this will be a nice way to get used to it so that I can work on my React projects.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published