typescript

typescript

Switch-case statement in typescript with examples

switch-case statement is used to run a block of code based on the result of an expression. This program will show you how to use switch-case in typescript.

Read
typescript

What is union type in typescript and how to use

union type in typescript is used to define a variable that can hold multiple types of values. In this post we will learn how to use union type with examples.

Read
typescript

3 different ways to split a string in typescript

Learn how we can split a string in typescript. We will learn three different ways to split a string in typescript. We can use the split method of string to split a string in typescript.

Read
typescript

Interface in typescript explanation with example

Learn what is interface in typescript with example. Interface is used to define the syntax of a class to follow.

Read
typescript

How to import JSON from a file in TypeScript

Suppose you need to work with a local json file in your typescript project. You have this file in your project folder, but how to import it? It is actually pretty easy. In this post, I will show you two different ways to import one JSON file in a typescript project.

Read
typescript

Type assertion in typescript explanation with example

Type assertion in typescript is used to set the type of a variable and tell the compiler not to infer this. Suppose, you are switching from JavaScript to TypeScript and you know the type of one variable, you can tell the typescript compiler that this is the type this variable will have and you shouldn't do any more type checking for it. This is called "type assertion". Type assertion is used for compile-time checks. You can set type of one variable as number, string or any other type. For example :.

Read
typescript

How to parse JSON in TypeScript

JSON or JavaScript Object Notation is an open standard file format used for transferring data. Parsing JSON data is really easy in Javascript or Typescript. Typescript doesn't have any different methods for JSON parsing. We can use the same JSON.parse method used with JavaScript.

Read
typescript

Different ways to convert a string to number in TypeScript

Casting a string to number in typescript requires Javascript methods. Typescript doesn’t provide any specific methods for this conversion. Again, we have a couple of different methods in Javascript that can convert one string to a number. In this post, I will show you different ways to do the conversion.With each example, I am using an array of different strings. Each example will try to convert each of these array elements to numbers.

Read
typescript

TypeScript add one or more elements to an array

Different ways to add one or more elements to the start, end and middle of an array in TypeScript. We will do that by using push, unshift, index notation, concat and splice methods with examples.

Read
typescript

How to iterate over an array in TypeScript

Learn how to iterate over an array in TypeScript in different ways. Learn by using a for loop, using for..in loop, for..of loop and forEach loop.

Read