You are here: Home / Topics / Page / 13

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