Found 128 Articles for TypeScript

How to automatically compile your TypeScript files with Visual Studio Code on OS X?

Mohit Panchasara
Updated on 31-Aug-2023 12:30:44

449 Views

TypeScript is a popular programming language that is widely used in the web development industry. It is an open-source, strongly typed, and object-oriented programming language that is a superset of JavaScript. TypeScript is very similar to JavaScript, but it has a few additional features that make it more powerful and efficient. One of the best things about TypeScript is that it can be compiled into JavaScript, which can be run in any browser or on any server. In this article, we will discuss how to automatically compile TypeScript files with Visual Studio Code on OS X. Visual Studio Code is ... Read More

Readonly Properties in TypeScript

Mohit Panchasara
Updated on 31-Aug-2023 12:24:44

147 Views

In TypeScript, properties are an essential part of defining the structure and behavior of objects. They allow us to encapsulate data and provide a way to access and manipulate it. By default, properties in TypeScript can be both read and write, meaning they can be both accessed and modified. However, there are scenarios where we may want to create properties that can only be read and not modified. This is where readonly properties come into play. Readonly properties provide a way to define properties that can only be accessed and not changed once they are assigned a value. They are ... Read More

TypeScript for Java/C# Programmers

Mohit Panchasara
Updated on 21-Aug-2023 15:04:43

96 Views

In this tutorial, we will discuss TypeScript, a great option for programmers who have experience with static typing languages like C# and Java. We can benefit from TypeScript's type system, which offers improved code completion, earlier error detection, and clearer communication between different parts of our program. It's essential to remember that TypeScript is based on JavaScript, which has some fundamental differences from traditional OOP languages. By understanding these differences, we can avoid common mistakes that programmers transitioning from C#/Java to TypeScript might make. Syntax Users can use the following syntax to create variables using TypeScript − let variableName: type ... Read More

Typescript - filter all matching objects in the object and its exactly the same children

Mohit Panchasara
Updated on 21-Aug-2023 15:03:33

690 Views

One common task in software development is filtering objects based on specific criteria. In this tutorial, we will explore how to filter all matching objects in an object and its exactly the same children using Typescript. This technique can be particularly useful when working with complex data structures or when extracting specific information from nested objects. We will utilize TypeScript's powerful features, such as type annotations and object manipulation, to achieve this. Recursive Function with Type Guards for Filtering Matching Objects and Their Children We can use a recursive approach to filter all matching objects in an object and it ... Read More

Structural typing in Typescript

Mohit Panchasara
Updated on 21-Aug-2023 15:00:36

178 Views

TypeScript, a superset of JavaScript, introduces static typing to JavaScript, allowing developers to catch potential errors and enhance code quality. One of the key features that set TypeScript apart is its support for structural typing. While other statically typed languages often rely on nominal typing, TypeScript embraces the concept of structural typing, which provides a more flexible and intuitive approach to type checking. In this tutorial, we will explore the concept of structural typing in TypeScript and its benefits and provide relevant examples to illustrate its usage. Understanding Structural Typing Structural typing is a type system that focuses on the ... Read More

Private, Public & Protected Access Modifiers in TypeScript

Mohit Panchasara
Updated on 21-Aug-2023 14:57:59

179 Views

Access modifiers are essential because they allow us to enforce encapsulation and define the boundaries of class member accessibility. With access modifiers, we can restrict access to certain members, ensuring they are only accessible within the class itself. We can also make members public, allowing them to be accessed from anywhere in our codebase. Furthermore, protected members enable access within the class and its derived classes. In this tutorial, we will explore the private, public, and protected access modifiers in TypeScript. Syntax Users can follow the syntax below to apply access modifiers to class members in TypeScript − class ClassName ... Read More

Is it possible to generate TypeScript declaration files from JS library?

Mohit Panchasara
Updated on 21-Aug-2023 14:54:04

168 Views

If you have ever worked with JavaScript libraries in your TypeScript projects, you may have encountered situations where you needed type information for those libraries. TypeScript declaration files, denoted with the .d.ts extension, provide type information for JavaScript code, enabling better static type checking and editor support in TypeScript projects. In this tutorial, we will explore different scenarios and methods for generating TypeScript declaration files from JavaScript libraries. We'll cover scenarios such as generating declaration files for existing JavaScript libraries, generating declaration files for your own JavaScript code, and leveraging tools like dts-gen and tsc to generate declaration files automatically. ... Read More

How to use Record type in typescript?

Mohit Panchasara
Updated on 21-Aug-2023 14:52:31

188 Views

In TypeScript, the Record type is a powerful tool that allows you to define an object type with specific keys and corresponding value types. This tutorial will guide you through the fundamentals of using the Record type, providing syntax explanations and practical examples along the way. Whether you're a beginner or already familiar with TypeScript, this tutorial will help you understand how to leverage the Record type effectively in your projects. Syntax The syntax to create a Record type in TypeScript is straightforward. The type definition starts with the keyword Record, followed by angle brackets () containing the key and ... Read More

How to Get Window History in TypeScript?

Mohit Panchasara
Updated on 21-Aug-2023 14:51:00

279 Views

The user’s history of visited web pages is represented via the window.history object. A history of the pages that have been loaded is stored in an array called the history object. The history object only provides a finite amount of information. The history object only has a few properties and methods since it is impossible to know where the current URL is located within the history object. The previous URL in the history list is loaded using the history.back() method. The second method of history is the forward() method, which loads the following URL in the history list. It is ... Read More

How to Fix Absolute Imports in TypeScript?

Mohit Panchasara
Updated on 21-Aug-2023 14:49:02

495 Views

Introduction When working on TypeScript projects, organizing and managing module dependencies is essential for maintaining a clean and scalable codebase. Absolute imports offer a convenient way to reference modules using a fixed path relative to the project's root directory. However, configuring and fixing absolute imports can sometimes be challenging, especially for beginners. In this tutorial, we will explore various scenarios where absolute imports may encounter issues and discuss practical solutions to resolve them. By the end, you'll understand how to fix absolute import problems in TypeScript effectively. Scenario 1: Missing TypeScript Configuration Before utilizing absolute imports, we must ensure that ... Read More

Advertisements