我可以在 TypeScript 中宣告可以通過點符號訪問的嵌套型別組嗎?
我想要做的是像下面的代碼:
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,
}
uj5u.com熱心網友回復:
你可以用命名空間做到這一點:
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
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/343879.html
標籤:打字稿
