typescript - 打字稿:多个可能的接口作为一个接口
问题描述
如果我有这样的变量:
let x: number | string | undefined;
是否可以创建一个支持所有这些类型的接口?就像是:
let x: MyCustomInterface;
谢谢!
解决方案
不,接口本身不支持联合。您可以创建一个类型别名:
type MyCustomType = number | string | undefined;
let x: MyCustomType;
推荐阅读
- r - 如何根据因子变量为 xyplot 的每个面板中的背景着色?
- javascript - 如何在没有 php 的 HTML 文件上显示我的数据库值?
- python - 从 Python 在控制台中运行 WinSCP 命令
- r - 如何将数字节点大小属性分配给边缘列表的一列?
- java - 仅在接收某些事件时才使用 spring 从 kafka 主题中消费
- reactjs - 带有 Express/Apache2/SSL 的 Socket.IO
- python - 如何在更新字典时从字符串变量中转义引号
- tableau-api - 如何仅为 Tableau 中的特定行激活工具提示?
- node.js - 图片显示在浏览器中,但无法使用代码下载(node.js)
- google-apps-script - 将 xls 转换为 Google 表格时将图表另存为图像 - Google 脚本