当前位置:网站首页>TypeScript-接口和类型别名异同
TypeScript-接口和类型别名异同
2022-06-11 07:54:00 【YY小怪兽】
1.都可以描述属性或方法
type MyType = {
name:string;
say():void;
}
interface MyInterface {
name:string;
say():void;
}
2.都允许拓展
interface MyInterface {
name:string;
say():void;
}
interface MyInterface2 extends MyInterface{
age:number;
}
let value:MyInterface2 = {
name:'lnj',
age:18,
say():void{
}
}
type MyType = {
name:string;
say():void;
}
type MyType2 = MyType & {
age:number;
}
let value:MyType2 = {
name:'lnj',
age: 18,
say():void{
}
}
3.type 可以声明基本类型别名,联合类型,元组等类型, interface不能
type MyType1 = boolean;
type MyType2 = string | number;
type MyType3 = [string, boolean, number];
4.type不会自动合并
interface MyInterface {
name:string
}
interface MyInterface {
age:number
}
let value:MyInterface ={
name:'lnj',
age:18
}
type MyType = {
name:string
}
type MyType = {
age:number
}
边栏推荐
- Sort - merge sort
- [codeforces1019e] raining season
- The solution of "no startup device" after running Bochs
- Bidirectional linked list simple template (pointer version)
- Session and session management technology
- Zero foundation self-study SQL course | union joint query
- Crawl Baidu Baipin dynamic page
- Image processing operation record
- [untitled] Weng_ C lesson 1
- [noip2016 d1t3] changing classrooms (expectation dp+floyd) (trap of extreme thinking!)
猜你喜欢

C language - growth diary-04- preliminary exploration of local variables (local variables)

C language function stack frame
![[untitled] Weng_ C lesson 1](/img/4e/41876093ef6b6a38909832f89e1495.jpg)
[untitled] Weng_ C lesson 1

学习《缠解论语》
![[IOT] project management: how to build a better cross functional team?](/img/df/28dbf0f7ba75d1bb3469cc15e70538.png)
[IOT] project management: how to build a better cross functional team?

如何开始参与开源社区

Collation of basic knowledge of intermediate development of Andrews (for interview)

用 Keras/TensorFlow 2.9 创建深度学习模型的方法总结

C language lesson 2

【IoT】项目管理:如何打造更好的跨职能团队?
随机推荐
Introduction to operations research
Long dialogue in June 2017
TiDB Cloud 上線 Google Cloud Marketplace,以全新一棧式實時 HTAP 數據庫賦能全球開發者
避免list的并发修改异常的几种方式
[atcoder1981] short diameter (graph theory thinking)
Closure and minimum dependency in database
2021-10-24
String Simulation Implementation
Using Tkinter to realize guessing numbers game
[software testing] 90% of the interviewers have been brushed out of such resumes
【AtCoder2387】+/- Rectangle
mpi
C. Manipulating History(贪心/哈希/思维/好题)
Classes and objects (medium)
multi-sig SC
Post - payload of interface test
Batch splice string
E regression test of this featured app
C language - Growth Diary -03- function definition and function prototype declaration
Image data enhancement (translation, rotation, brightness transformation, flipping, adding Gaussian noise, scaling, cropping)