ts 中 type 与 interface 的区别

类型别名 type类型别名用来给一个类型起个新名字,使用 type 创建类型别名,类型别名不仅可以用来表示基本类型,还可以用来表示对象类型、联合类型、元组和交集 12345678910111213141516171819202122232425// 基本类型type userName = string;// 联合类型type userId = string | number;// 数组类型t...

发布于 TS

typeScript 中的数组类型定义

声明和初始化数组在 TypeScript 中声明和初始化数组也很简单,和声明数字类型和字符串类型的变量也差不多,只不过在指定数组类型时要在类型后面加上一个中括号 [] 语法格式 1const array_name: dataype[] = [val, val2]; 示例 声明一个 string 类型的数组 1const character: string[] = ["杨过&quo...

发布于 TS

typeScript typeof 操作符

js 表达式中的 typeof 用来返回一个变量的基本数据类型如 string、number、function、object 12345678910typeof 1; // numbertypeof true; // booleantypeof 'hello world'; // stringtypeof function () {}; // func...

发布于 TS

typeScript 中的 ! ?

!的用法1234567891011121314{ // 用在赋值的内容时,使 null 和 undefined 类型可以赋值给其他类型并编译通过 // 表示该变量值可空 let y: number; let a: string; // y = null // 无法通过编译 // y = undefined // 无法通过编译 y = null...

发布于   更新于 TS

typeScript 数据类型笔记

元组(tuple) 概念:就是一个规定了元素数量和每个元素类型的“数组”,而每个元素的类型,可以不相同 语法: 123456789// let 元组名: [类型1, 类型2, 类型3] = [值1, 值2, 值3];let tup1: [string, number, boolean] = ['哈哈~~', 18, true];// 只能输入两个,超出即报错const ...

发布于   更新于 TS