What is typescript used for? What can be done?

不言
Release: 2018-10-20 11:54:29
Original
13903 people have browsed it

We are very familiar with javascript, but what is typescript? Typescript is actually a free and open source programming language developed by Microsoft. It is a superset of JavaScript and essentially adds optional static typing and class-based object-oriented programming to the language. The following article will introduce to you what typescript is used for? What can be done? Anyone who is interested can take a look.

The first thing we need to know is that the language finally compiled by Typescript is js. It allows us to better use js instead of replacing it with a completely new language.

Let’s look directly atWhat is the use of typescript? What can be done?

1. Strong typing at compile time

TypeScript has designed a set of type mechanisms to ensure strong type judgment at compile time.

The simplest way is to declare the type of the variable. When typescript's powerful strong typing is checked by the compiler, any other type of assignment will cause a compilation error. At this time, we only need to change it according to the error report. The corresponding parameters are enough.

One of the biggest benefits of strong typing is intelligent prompts. For example, you can know what properties and methods the current variable has, which is very convenient.

2. Modularization

Using TypeScript’s keyword module can achieve an effect similar to a namespace, and export can control whether it is accessed externally. For example :

module Project{ export module Core{ function FuncA(){ } export function FuncB(){ FuncA();//ok } } } module Project.Core{ export function FuncC(){ FuncA();//error FuncB();//ok } } Project.Core.FuncA();//error Project.Core.FuncB();//ok Project.Core.FuncC();//ok
Copy after login

It can be seen from this example that modules can be nested. '.' is used as the separator when accessing. You can also use '.' as the separator to abbreviate the nesting of modules. Only with the export keyword can be accessed externally, and modules can be merged, but non-export objects cannot be accessed under other modules, even if they have the same name, such as FuncA().

3. Existing class libraries can be easily used

Similar to C header files, TypeScript allows you to define some declarations and declare existing variables and type, then you can easily call existing class libraries in a strongly typed way.

The above is the entire content of this article. For more other exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !

The above is the detailed content of What is typescript used for? What can be done?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!