TypeScript

TypeScript

1 安装

单独文件需要安装,项目不需要(例如vite)

npm install -g typescript
tsc -v  //查看当前版本号

image-20240310112657635

image-20240310112815249

image-20240310112838259

2 基本类型

image-20240310112911160

2.1 字符串类型

image-20240310113604794

2.2 数字类型

image-20240310113848643

如果变量没有写类型,默认是第一个赋值的类型

2.3 布尔类型

image-20240310114059690

image-20240310114523354

 npm i @types/node --save-dev
 npm i ts-node -g   
 ts-node xxx.ts

image-20240310222338087

3 Any类型和unknown顶级类型

3.1 any

image-20240310223354586

3.2 unknown

image-20240310223455985

区别1

image-20240310223848931

image-20240310223926722

4 数组

image-20240310224448457

image-20240310224815318

5 联合类型

image-20240310225001573

image-20240310225557007

6 类型别名

image-20240310225702696

image-20240310225958511

7 函数类型 - 参数和返回值

image-20240311211456352

image-20240311211517496

image-20240311211809885

image-20240311212442579

image-20240311212508366

函数类型-void类型

image-20240311212649363

image-20240311213031817

image-20240311212951973

函数类型-可选参数

image-20240311213252812

image-20240311213454997

image-20240311213942648

对象类型

使用类型别名

image-20240311221712420

image-20240311214325657

image-20240311215017662

带有参数的方法类型

image-20240311215252637

image-20240311215540338

箭头函数形式的方法类型

image-20240311215635844

image-20240311215807597

任意属性[propName: string]

image-20240311221316619

image-20240311221141851

只读属性 readonly

image-20240311221403924

image-20240311221537893

对象类型-接口

image-20240311222838348

image-20240311222856602

image-20240311222750182

interface vs type

image-20240311222946708

image-20240311223042973

接口继承

image-20240311223211915

image-20240311223305537

交叉类型

image-20240311223519156

image-20240311223549913

元组类型

image-20240311224035430

image-20240311224456004

image-20240311224418949

类型推论

image-20240311224604209

image-20240311224822826

类型断言

image-20240311224900565

image-20240311225009887

image-20240311225047732

泛型

image-20240311225431019

泛型别名

image-20240311225651739

image-20240311230736481

image-20240311230108260

image-20240311230224038

image-20240311230412751

image-20240311230601363

泛型接口

image-20240312205522162

image-20240312210157409

image-20240312205858030

image-20240312210012858

泛型函数

image-20240312210411919

image-20240312210703963

image-20240312210637790

image-20240312210813573

TypeScript 与 vue

image-20240312211058487

1 创建vite项目

npm create vite@latest  

image-20240312212048346

npm i //安装相关依赖

image-20240312212243561

npm run dev //运行项目

2 ref 与 ts

image-20240312213320883

image-20240312215528585

image-20240312215551451

image-20240312215612534

image-20240312213928085

image-20240312214421069

image-20240312214452849

image-20240312214834613

3 reactive 与 ts

image-20240312215710869

image-20240312221158834

image-20240312221456647

如果是数组,使用reactive,只能push,总结就是不能改变对象的指针

4 computed与ts

image-20240313202416243

image-20240313203123718

image-20240313202639673

image-20240313203038965

5 defineProps 与 ts

image-20240313204110116

image-20240313204035149

image-20240313205520439

image-20240313205741662

image-20240313210931591

image-20240313204921454

image-20240313205042356

image-20240313210102772

image-20240313210650017

6 defineEmits 与 ts

image-20240313210837707

image-20240313211546344

image-20240313211654543

image-20240313211737819

image-20240313213126286

7 事件处理与ts

image-20240313221001610

image-20240313221028977

image-20240313220915217

8 Template Ref 与 ts

image-20240313221626132

image-20240313222153259

image-20240313222503761

ts 类型声明文件

image-20240313222911226

image-20240313223138737

内置类型声明文件

image-20240313223223459

第三方库类型声明文件

image-20240313223820207

自定义类型声明文件

image-20240313224347607

image-20240313224722150

image-20240313225013127

image-20240313225126819

image-20240313225347271

image-20240313225456775

posted @ 2024-03-14 21:27  千夜ん  阅读(8)  评论(0编辑  收藏  举报