Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在TypeScript中使用嵌套类型?_Typescript - Fatal编程技术网

在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']) => {
  //
}