typescript - 在 TypeScript 中使用嵌套类型?
问题描述
我想将类型添加到应该接收items
字符串数组的函数中:
type Inputs = {
foo: string
items: string[];
};
const myFunction = (items: string[]) => {
//
}
上面的代码有效,但是有没有办法从 Inputs 类型中获取类型?所以像:
const myFunction = (items: Inputs.items) => {
//
}
解决方案
当然可以,但只需使用括号表示法:
type Inputs = {
foo: string
items: string[];
};
const myFunction = (items: Inputs['items']) => {
//
}
推荐阅读
- java - 当用户未连接到互联网时写入 Firebase 数据
- android - 如何用关键帧控制边距?
- css - Highcharts xrange 样式
- dataweave - 我正在尝试使用两个字段和 sum 进行分组,但似乎无法使其对我有用。任何帮助将非常感激
- mysql - 忽略重复条目并在 EF Core 中的 DbContext.SaveChanges() 上提交成功的条目
- docusignapi - DocuSign API - formData 数组和接收者FormData 数组之间的区别
- node.js - 如何以有意义的方式将我的 redux 数据存储在 MongoDB 中?
- vuejs2 - 方法“load”未在实例上定义,但在集成 @syncfusion/ej2-vue-maps 包时出现错误时引用
- ios - 当设备“A”尝试连接设备“B”时,设备“A”的 BT 与 iPhone 自动断开连接
- python-3.x - Python错误“AttributeError:模块'scipy.misc'没有属性'logsumexp'”