我具有Query
属性的这种getBankAccounts
类型:
export type Query = {
getBankAccounts: GetBankAccountsResponseOrUserInputRequest,
};
但是它返回GetAccountsResponse
或UserInputRequest
:
export type GetBankAccountsResponseOrUserInputRequest = GetAccountsResponse | UserInputRequest;
我只想Pick<Query, "getBankAccounts">
的响应类型:GetAccountsResponse
。
非常感谢您的帮助。
答案 0 :(得分:0)
type BankAccountQuery = Pick<Query, Exclude<keyof Query, 'getBankAccounts'>> & { getBankAccounts: GetAccountsResponse }
或者您可以使用Overwrite
助手:
type Overwrite<T, U extends { [K in keyof T]?: any }> = U & Pick<T, Exclude<keyof T, keyof U>>;
type BankAccountQuery = Overwrite<Query, {getBankAccounts: GetAccountsResponse }>;
请注意,这将选择Query
类型的任何其他字段(如果有)。如果您只想选择一个字段,那么您可以简单地声明另一种类型?
type BankAccountQuery = {
getBankAccounts: GetAccountsResponse;
}