You are here: Home / Topics / Search / typescript
Showing 18 Search Results for : typescript

Project Structure - TypeScript

Filed under: TypeScript on 2024-03-18 12:45:47
Create two folders with the name ‘src’ and ‘public’. ‘src’ will be responsible to keep ts files & ‘public’ will be responsible to keep js & html files.Execute the following commands:tsc --initThis command will be responsible to create a tsconfig.json file. Open the tsconfig.j

Parallel Programming with Axios - TypeScript

Filed under: TypeScript on 2024-03-18 12:35:28
Example 1:As we can see from the output, all three sleep functions run and they print out how long they have run for. We can also see how long the main function has run, just over 3000ms. This shows that we are running these tasks in parallel, if we weren't, the main function would have run for abou

Consuming Rest Api - Typescript

Filed under: TypeScript on 2024-03-18 12:28:53
APIs are mechanisms that enable two software components to communicate with each other using a set of definitions and protocols. For example, the weather bureau's software system contains daily weather data.Example 1: Fetch Data & use JSON.stringifymain.tsimport axios from 'axios';async function

Generics in Typescript

Filed under: TypeScript on 2024-03-18 12:15:16
The purpose of generics in programming languages, including TypeScript, is to provide a way to write reusable code that can work with different types while maintaining type safety. Generics allow you to define types or functions that can adapt to various data types, without sacrificing compile-time 

Indexable Type Interface - Typescript

Filed under: TypeScript on 2024-03-18 12:04:22
In TypeScript, an indexable type interface allows you to define a type that can be accessed using indexing, similar to how you access elements in an array or properties in an object. This feature allows you to specify the types for indexing operations using specific key types.To define an indexable 

Excess Property Checks in Interface - Typescript

Filed under: TypeScript on 2024-03-18 11:57:41
In TypeScript, excess property checks occur when you try to assign an object literal to a variable or parameter with a defined type or interface that doesn't include all the properties of the object literal. By default, TypeScript performs excess property checks to ensure type safety and prevent pot

Optional Property interface typescript

Filed under: TypeScript on 2024-03-18 11:50:20
In TypeScript, you can define optional properties in an interface by appending a question mark (?) to the property name. This allows you to specify that a property is not required to be present in objects that implement the interface.Example 3: Optional Propertyindex.ts:interface Person {  &nbs

Interface Duck type in Typescript

Filed under: TypeScript on 2024-03-18 11:48:38
Duck Typing is a way of programming in which an object passed into a function or method supports all method signatures and attributes expected of that object at run time. The object's type itself is not important. Rather, the object should support all methods/attributes called on it.It refers to the

Interface in Typescript

Filed under: TypeScript on 2024-03-18 11:41:03
In TypeScript, an interface is a way to define the structure of an object. It specifies the properties and methods that an object should have. Interfaces are used for type checking during development and for documentation purposes.Example 1:index.ts:interface Person {name: string;age: number;greet: 

Abstract Class in Typescript

Filed under: TypeScript on 2024-03-18 11:37:35
Abstraction in TypeScript is a concept that allows you to create classes with abstract methods and properties. Abstract classes cannot be instantiated directly but serve as a blueprint for other classes to inherit from.Example 1:index.ts:abstract class Animal {name: string;constructor(name: string) 

Inheritance in TypeScript

Filed under: TypeScript on 2024-03-18 11:36:27
Inheritance is a mechanism that allows a class to inherit properties and methods from another class. It enables code reuse and promotes the concept of a hierarchical relationship between classes. TypeScript supports single inheritance, meaning a class can only inherit from a single base class. To im

TypeCasting in Typescript

Filed under: TypeScript on 2024-03-18 11:11:32
TypeScript supports typecasting, which allows you to explicitly change the type of a value. There are following ways to perform typecasting in TypeScript: using the as keyword and using angle bracket syntax (<>).In TypeScript, assertion and typecasting are often used interchangeably, but they 

TypeScript - Basic Types of Data

Filed under: TypeScript on 2024-03-18 11:01:22
JavaScript has three very commonly used primitives: string, number, and boolean. Each has a corresponding type in TypeScript. string represents string values like "Hello, world" number is for numbers like 42. JavaScript does not have a special runtime value for integers, so there’s 

Singleton Design Pattern - TypeScript

Filed under: TypeScript on 2024-03-14 17:15:36
The Singleton pattern can be useful in various scenarios where you need to ensure that there is only one instance of a class and provide global access to that instance. Some real-time use cases of the Singleton pattern include:Database Connections: When working with a database, you may want to have 

Creating Class in Typescript

Filed under: TypeScript on 2024-03-14 11:08:37
TypeScript offers full support for the class keyword introduced in ES2015.Class MembersHere’s the most basic class - an empty one:class Point {}This class isn’t very useful yet, so let’s start adding some members.FieldsA field declaration creates a public writeable property on a class:class Po

TypeScript Overview and Installation Guides

Filed under: TypeScript on 2024-03-14 10:06:45
TypeScript is an open-source language that is developed and maintained by Microsoft under the Apache 2 license. TypeScript is a strongly typed superset of JavaScript which compiles to plain JavaScript. It needs a compiler to compile and generate in a JavaScript file. TypeScript is the ES6 

Concepts of Typescript

Filed under: TypeScript on 2024-03-14 10:04:15
TypeScript is a programming language developed by Microsoft that extends JavaScript by adding static typing to it. It aims to enhance the development experience by providing better tooling, error checking, and code organization. Here are some key concepts in TypeScript: Static Typing: TypeScrip