MST
星途 面试题库

面试题:TypeScript实现WebSocket双向类型校验的基础类型定义

在TypeScript实现WebSocket双向类型校验场景中,假设服务器端发送的数据结构为 { message: string, timestamp: number },客户端发送的数据结构为 { action: 'connect' | 'disconnect', data: any },请分别定义这两种数据结构对应的TypeScript类型。
46.8万 热度难度
前端开发TypeScript

知识考点

AI 面试

面试题答案

一键面试
// 服务器端发送的数据结构类型
type ServerToClientData = {
    message: string;
    timestamp: number;
};

// 客户端发送的数据结构类型
type ClientToServerData = {
    action: 'connect' | 'disconnect';
    data: any;
};