English 中文(简体)
如何使用带宽变量的“<T”,U?
原标题:How to use Extract<T, U> with nested variant?
  • 时间:2023-08-25 01:57:49
  •  标签:
  • typescript

I m 处理产生型号的问题。 一份普通照会正向我提供两种类型之一,我希望逐一介绍。

类型:

type Add = {
    type:  add ;
    id: string;
}
  
type Remove = {
    type:  remove ;
    id: string;
}
  
type Action = Add | Remove;

type addType = Extract<Action, {type:  add }>;
    // ^? Add

然而,我的变量描述不同:

type ActionsCombined = {
    type:  add  |  remove ;
    id: string;
}

type addTypeCombined = Extract<ActionsCombined, {type:  add }>;
    // ^? never

两者似乎与我相当,但型号却看不到。 是否有办法从<条码>中提取<条码>+/条码>备选案文?

https://www.typescriptlang.org/playsl=2&ssc=17&pln=3&pc=16#code/C4TwgpgBAggJnKBevAUFLVSQFxQDkAhgoQNybYCWcBAzsA7UB2A5PQL5XQBABCAFA9DgKDNh

或者,是否可以将nes变式代表制成两个无关的变量?

问题回答




相关问题
store data in memory with nestjs

I am trying to persist some data in my nestjs server so I can then use that data in my client app through http requests. I have created a products.service.ts file with the function getAllData() that ...

React Hook Form Error on custom Input component

I am having a problem when I use react hook form + zod in my application, in short the inputs never change value and I get the following error in the console: Warning: Function components cannot be ...

Updatable promises using proxy in JavaScript

EDIT: I ve updated this question, and the old question is moved here. A POC can be found on this jsfiddle or the snippet below GOAL: The goal here is to make or rather simulate a promise that can be ...

热门标签