typescript - Typescript - 具有任意数量键值的对象
问题描述
我正在尝试编写一个接口来处理这样的数据:
interface SessionList {
appInfo: Object(string: string | null);
}
appInfo 下可能有 0 到多个项目。我正在尝试找到正确的语法,但没有运气 - 目前在:
appInfo: Object(string: string | null);
有任何想法吗?
解决方案
任何一个
interface AppInfo {
[key: string]: string | null;
}
或者
Record<string, string | null>
更新:
let obj: { appInfo: Record<string, string | null> };
interface SessionList {
appInfo: Record<string, string | null>;
}
let obj: SessionList;
推荐阅读
- kotlin - 如何在 Kotlin 中编写一个打开然后关闭应用程序的测试
- amazon-web-services - 将 Redshift 集群的大小从 dc1.8xlarge 调整为 ds2.8xlarge
- angular - Nativescript 和 Angular 路由 - URL 段错误
- php - 从多维数组中调用单个数据
- ruby-on-rails - Heroku rake db:迁移失败且没有错误
- rabbitmq - 网络故障后进程保留在 RabbitMQ 服务器消费者列表中
- php - 从 Windows 路径读取到 Linux 服务器时 PHP opendir 失败
- oracle - 如何为个人使用的 Oracle 数据库设置新连接?
- laravel - Laravel Eloquent 的自定义排序
- bash - 我正在尝试从我刚刚启动的实例中获取公共 IP