Original link: https://grimoire.cn/js/typescript-1.html
As a superset of JavaScript
, typescript
provides strongly typed features on the basis of JavaScript
, which can significantly reduce the output of bugs when developing programs written in typescript
.
base type
Although it is also a strongly typed language, typescript
obviously has looser restrictions on types than golang
and Rust
. For example, in typescript
, there is no distinction between int
, int32
, int64
, float
and other types, but number
is used directly type to refer to all numeric types
/* * @Author: NorthCity1984 * @LastEditTime: 2022-07-26 00:17:49 * @Description: * @Website: https://grimoire.cn * Copyright (c) NorthCity1984 All rights reserved. */ // number let num:number = 123; // string let str:string = "hello from NorthCityChen"; // boolean let isBoolean:boolean = true; // array let arr_num:number[] = [1, 2, 3, 4, 5]; let arr_str:string[] = ["hello", "world", "from", "NorthCityChen"]; // tuple let tuple:[string, number] = ["hello", 123]; // enum enum Color {RED, GREEN, BLUE, YELLOW}; let c:Color = Color.BLUE; // void: 用于标识方法的返回值的类型// null: 表示对象缺失// undefined: 未定义的值// never: 代表从不会出现的值// any: 任意类型,typescript会自动猜测变量类型
This article is reprinted from: https://grimoire.cn/js/typescript-1.html
This site is for inclusion only, and the copyright belongs to the original author.