简体   繁体   English

我可以在 TypeScript 中声明可以通过点符号访问的嵌套类型组吗?

[英]Can I declare nested group of type in which can access by dot-notation in TypeScript?

Can I declare nested group of type in which can access by dot-notation in TypeScript?我可以在 TypeScript 中声明可以通过点符号访问的嵌套类型组吗?

What I want to do is like the code below:我想要做的是像下面的代码:

import { FuncA, FuncB } from './types' // <-- how should I write code in `types.ts` to access types like `FuncA.Param1` ?

export default class MyFunc {
  funcA(param1: FuncA.Param1, param2: FuncA.Param2): FuncA.Response {
    return blabla
  }

  async funcB(param1: FuncB.Param): Promise<FuncB.Response> {
    return blabla
  }
}

export {
  FuncA,
  FuncB,
}

You can do that with namespaces :你可以用命名空间做到这一点:

export namespace FuncA {
  export type Param1 = string | number
  export type Param2 = boolean
  export type Response = boolean
}

export namespace FuncB {
  export type Param = number
  export type Response = boolean
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM