Classes in typescript - 6thday of 100daysofcoding

Classes in typescript - 6thday of 100daysofcoding

Typescript is fully supported to work with modern javascript keyword class.

Generally, classes are blueprints to make properties and methods for objects. let's see how to define property and methods in the class. if you want some property then you have to add the constructor function, so when the class is initiated property is assigned to the instance. if you don't pass during assigning or forgot to assign, ts will give an error.

No alt text provided for this image

If there are any params in the method of a class or any return value, then we can use the same syntax as a normal function.

No alt text provided for this image

Extend method from other classes

No alt text provided for this image

Abstract class

we cannot initialize the abstract class. it's made to reusable some functionality. if we don't define the abstract method defined in the abstract class from children then it will give an error.

No alt text provided for this image

public, private, and protected modifiers

No alt text provided for this image

Shorthand for assign value in constructor

No alt text provided for this image

要查看或添加评论,请登录

Meet Vaghasiya的更多文章

  • START EXPRESS JS WITH TYPESCRIPT

    START EXPRESS JS WITH TYPESCRIPT

    In this article, we will learn How to install express js with typescript and minimal setup configuration of…

  • Redux with typescript

    Redux with typescript

    Let's see how we use redux with typescript install react typescript app npx create-react-app typescript-practise…

  • Using typescript with react.

    Using typescript with react.

    Here we will learn step by step process for starting the #typescript with a #reactjs . Steps: create a typescript app.

  • Index signature and keyof operator in Typescript

    Index signature and keyof operator in Typescript

    Index signature Let's say we have two types of objects. and you want to make a common function that returns total marks.

  • Use generics like pro

    Use generics like pro

    There is a rule in programming called DRY- don't repeat yourself. generics help us to use this convention in typescript.

  • High-level overview of type and interface in Typescript

    High-level overview of type and interface in Typescript

    Standard javascript object is a map of key: value pairs. When we define an object with properties (keys) and values…

  • Functions and object in typescript- DAY5 OF 100DAYSOFCODE

    Functions and object in typescript- DAY5 OF 100DAYSOFCODE

    Functions: Functions are a very important part of any programming language as it provides reusability. let's see, how…

  • ARRAY AND TUPLES IN TYPESCRIPT - DAY4 OF #100DAYSOFCODE

    ARRAY AND TUPLES IN TYPESCRIPT - DAY4 OF #100DAYSOFCODE

    ARRAY IN TYPESCRIPT In typescript, typescript need to know type of each items in array. so it will tell us error if we…

  • TYPE- any in ts - DAY3 OF 100DAYSOFCODE

    TYPE- any in ts - DAY3 OF 100DAYSOFCODE

    Any type in typescript in the previous article, if you remember the last moment, if we don't declare and initialize…

    2 条评论
  • Type and Type system in Typescript - DAY2 of 100 DAYSOFCODE

    Type and Type system in Typescript - DAY2 of 100 DAYSOFCODE

    What is a type system? When we learn any programming languages, first they introduces with various data-types of that…

社区洞察

其他会员也浏览了