Method | Description |
---|---|
charAt() | Returns the character at the given index |
concat() | Returns a combination of the two or more specified strings |
indexOf() | Returns an index of first occurrence of the specified substring from a string (-1 if not found) |
replace() | Replaces the matched substring with a new substring |
split() | Splits the string into substrings and returns an array |
toUpperCase() | Converts all the characters of the string into upper case |
toLowerCase() | Converts all the characters of the string into lower case |
charCodeAt() | Returns a number that is the UTF-16 code unit value at the given index |
codePointAt() | Returns a nonnegative integer Number that is the code point value of the UTF-16 encoded code point starting at the specified index |
includes() | Checks whether a string includes another string |
endsWith() | Checks whether a string ends with another string |
LastIndexOf() | Returns the index of last occurrence of value in the string |
localeCompare() | Checks whether a string comes before, after or is the same as the given string |
match() | Matches a regular expression against the given string |
normalize() | Returns the Unicode Normalization Form of the given string. |
padEnd() | Pads the end of the current string with the given string |
padStart() | Pads the beginning of the current string with given string |
repeat() | Returns a string consisting of the elements of the object repeated in the given times. |
search() | Searches for a match between a regular expression and a string |
slice() | Returns a section of a string |
startsWith() | Checks whether a string starts with another string |
substr() | Returns a string beginning at the specified location and of the given characters |
substring() | Returns a string between the two given indexes |
toLocaleLowerCase() | Returns a lower case string while respecting current locale |
toLocaleUpperCase() | Returns an upper case string while respecting current locale |
trim() | Trims the white space from beginning and end of string |
trimLeft() | Trims the white space from left side of the string |
trimRight() | Trims the white space from right side of the string |
Install TypeScript
There are three ways to install TypeScript:
- Install TypeScript as an NPM package on your local machine or in your project.
- Install TypeScript NuGet Package in your .NET or .NET Core project.
- Install TypeScript as a Plug-in in your IDE (Integrated Development Environment).
Install TypeScript using NPM
NPM (Node.js package manager) is used to install the TypeScript package on your local machine or a project. Make sure you have Node.js install on your local machine. If you are using JavaScript frameworks for your application, then it is highly recommended to install Node.js.
To install or update the latest version of TypeScript, open command prompt/terminal and type the following command:
npm install -g typescriptThe above command will install TypeScript globally so that you can use it in any project. Check the installed version of TypeScript using the following command:
tsc -vExecute the following command to install the TypeScript to your local project as dev dependency.
npm install typescript --save-devInstall TypeScript as NuGet Package
For .NET or .NET Core projects, TypeScript can be installed as a NuGet package in your project.
The NuGet package Microsoft.TypeScript.MSBuild is an MSBuild task for TypeScript, which will automatically compile all .ts
files to .js
files as per tsconfig.json
configuration when you build your project.
To install the TypeScript NuGet package, open NuGet Package Manager by right-clicking on a project node, click Manage NuGet Packages..
, and search for typescript in the Browse
tab. It will list all the packages related to TypeScript.
Select Microsoft.TypeScript.MSBuild and click on the Install button.
This will install TypeScript in your local ASP.NET project.
TypeScript Visual Studio Extension
If your project type does not support the NuGet packages, then you can use TypeScript Visual Studio Extension. You can find and install the extension in Visual Studio from Tools > Extensions and Updates menu.
Visual Studio Code comes with built-in support for TypeScript.
Install TypeScript Plug-in in your IDE
You can install an IDE specific TypeScript package or plugin for your IDE.
A few examples of plugins for popular code editors are:
- Atom-TypeScript: a TypeScript language service for Atom developed by TypeStrong.
- TypeScript IDE for Eclipse: an Eclipse plugin developed by Angelo Zerr.
- TypeScript Plug-in for Eclipse: an Eclipse plugin developed by Palantir.
- WebStorm includes TypeScript support out of the box.
Visit TypeScript Github Repository for the full list of IDEs that support TypeScript development.
TypeScript Playground
TypeScript provides an online playground https://www.typescriptlang.org/play to write and test your code on the fly without the need to download or install anything.
This is a great place for beginners to learn TypeScript and try different TypeScript features. You also have the option to share your code via a shareable link provided by the playground.