Extract a non-exported type from type

  Kiến thức lập trình

I want to get a type from a library that is a development dependency, I don’t want it to be required in production.

The exported type is:

export type NodeState =
  | NodeStateSchema0
  | NodeStateSchema1
  | NodeStateSchema3
  | NodeStateSchema4
  | NodeStateSchema5
  | NodeStateSchema7
  | NodeStateSchema10
  | NodeStateSchema14
  | NodeStateSchema29
  | NodeStateSchema30
  | NodeStateSchema31
  | NodeStateSchema35;

If I use this type directly I get NodeStateSchema0 and I want NodeStateSchema35 but the NodeStateSchema* types are not exported, so I can’t use it directly. How I can do something like Extract<NodeState, "NodeStateSchema35">?

PS: The library is @zwave-js/server and the definition of the type NodeState

LEAVE A COMMENT