在TypeScript中使用嵌套类型?
我想将类型添加到应该接收字符串项数组的函数中:在TypeScript中使用嵌套类型?,typescript,Typescript,我想将类型添加到应该接收字符串项数组的函数中: type Inputs = { foo: string items: string[]; }; const myFunction = (items: string[]) => { // } 上面的代码可以工作,但是有没有办法从输入类型中获取类型?比如: const myFunction = (items: Inputs.items) => { // } 当然可以,但只需使用括号表示法即可: type In
type Inputs = {
foo: string
items: string[];
};
const myFunction = (items: string[]) => {
//
}
上面的代码可以工作,但是有没有办法从输入类型中获取类型?比如:
const myFunction = (items: Inputs.items) => {
//
}
当然可以,但只需使用括号表示法即可:
type Inputs = {
foo: string
items: string[];
};
const myFunction = (items: Inputs['items']) => {
//
}