You are here: Home / Topics / Page / 5

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: