typescript - 如何导出可以是对象或布尔值的类型而不会引发未定义的属性错误?
问题描述
嗨,我想创建一个这样的类型:
export type LoginResult = {
readonly token: string;
readonly renewal_token: string;
} | boolean;
但是当一个声明一个常量作为这种类型,并且需要访问令牌或更新时,它会抛出:
Property 'token' does not exist on type 'LoginResult'.
Property 'token' does not exist on type 'false'.ts(2339)
我怎样才能做到这一点 ?有没有其他更好的方法来实现这一目标?谢谢你。
解决方案
推荐阅读
- python - Beautifulsoup 的网页抓取问题
- javascript - 带有 Javascript 的响应式 Bootstrap 进度条
- python - 矢量化和广播
- html - links.append() 不会将所有图像链接显示为列表
- java - 如何对地图进行排序
? - java - 未授权 (401) 异常,在 java 中使用 EWS 发送邮件时
- c++ - 如何避免同一个列表上的多线程中的空指针?
- php - 如何在 WooCommerce 中遍历订单商品数量
- flutter - 我想在我的颤振应用程序中通过 onPressed 方法生成卡片。谁能给我一个路线图...?
- ubuntu - 如何使用共享文件的确切版本安装 OpenMPI?