当前位置:网站首页>Typescript interface and type alias similarities and differences
Typescript interface and type alias similarities and differences
2022-06-11 07:59:00 【YY little monster】
1. Can describe properties or methods
type MyType = {
name:string;
say():void;
}
interface MyInterface {
name:string;
say():void;
}
2. Are allowed to expand
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 You can declare basic type aliases , Joint type , Tuples and so on , interface You can't
type MyType1 = boolean;
type MyType2 = string | number;
type MyType3 = [string, boolean, number];
4.type It doesn't merge automatically
interface MyInterface {
name:string
}
interface MyInterface {
age:number
}
let value:MyInterface ={
name:'lnj',
age:18
}
type MyType = {
name:string
}
type MyType = {
age:number
}
边栏推荐
猜你喜欢

Data visualization and Matplotlib

Detailed explanation of character function and string function (including simulation implementation)

Servlet

记一次忽略@SuppressLint(“NewApi“)提示引发的血案

The solution of "no startup device" after running Bochs

Bladed入门教程(视频)

C language - Growth Diary -03- function definition and function prototype declaration

2022.6.6 extra long growth simulation

C# 微信上传Form-data

安卓初中级开发基础知识整理(面试自用)
随机推荐
C language - growth diary-04- preliminary exploration of local variables (local variables)
Space geometry
SOCKET【5】- struct linger 用法
C wechat upload form data
Understanding of Poisson distribution and Poisson process and Erlang distribution and their relations (important theories in queuing theory and operational research)
2022.6.6 特长生模拟
Tutoriel de démarrage bladed (vidéo)
2022.6.6 extra long growth simulation
Detailed explanation of shift operator and bit operator in C language
Remote office experience sharing | community essay solicitation
2021-10-17
TypeScript-类型保护
远程办公经验分享 | 社区征文
Alchemy experience (model training of deep learning) the necessity of timely adjusting training parameters for some situations (the adjustment of learning rate LR is the primary) summarizes some metho
自定义ViewGroup的知识点总结-持续更新
Return in foreach and break in for
Remote office experience | community essay solicitation
TypeScript-头文件使用细节
空间几何
放大镜子效果图