[typescript] interface和type有什么关系?

在这里插入图片描述

type 和interface

即使不知道他们的区别,也是可以学习编程的。不要因为搞不懂type和interface的区别,而丧失了对编程的兴趣。

import type {XYZ} from ‘xxxx’

一般情况type和interface都很类似。
Both can be used to describe the shape of an object or a function signature. But the syntax differs.

https://blog.logrocket.com/types-vs-interfaces-typescript/

?:可选属性,?:说明这个属性可以不存在

errorMessage?: string;

最近有typescript和python代码互转的需求。
但是会发现除了基本的逻辑流程的转写,还涉及到数据结构的转写。而且数据结构的转写比逻辑的的转写有时候还要烧脑。

比如下面的typescript怎么转写成python的数据类型?

// Conversation tracking types for maintaining context across interactions

export interface ConversationMessage {
   
   
  id: string;
  role: 'user' | 'assistant';
  content: string;
  timestamp: number;
  metadata?: 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值