Quantcast
Channel: Active questions tagged visual-studio-code - Stack Overflow
Viewing all articles
Browse latest Browse all 97355

Is there a way to show a normalized version of a type in typescript?

$
0
0

There are plenty of parametrized type aliases that are used in typescript and it can sometimes be difficult to determine what the actual type is below all the abstraction layers. Is there some way to normalize a concrete type remove all type aliases from it?

For example, if I have these types:

type Maybe<T> = T | null
type Num = number
type Base = {
  a: Num
  b: boolean
  c: Maybe<{ x: Num }>
}

type Hello = Pick<Base, 'a' | 'c'>

I want some way to show that Hello is the same as:

type Hello = {
  a: number
  c: { x: number } | null
}

I am also interested in if there is a way to do shallow normalization and convert Pick<Base, 'a' | 'c'> into

type Hello = {
  a: Num
  c: Maybe<{ x: Num}>
}

Viewing all articles
Browse latest Browse all 97355

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>