In version 4.2, TypeScript improved type alias preservation. This means that if you hover over a variable that was declared using a type alias, IDEs will show you the friendly name of that type alias rather than the raw structure of the type.
There are, however, cases where this isn't desirable. Consider the following example:
interface Animal {
name: string;
speed: number;
legCount: number;
}
let foo: Omit<Animal, 'legCount' | 'speed'>;
This uses the utility type Omit
to create a new type that is a subset of Animal
. Hovering over the variable foo
shows this tooltip:
This tells me how the type was constructed, but it doesn't tell me anything about the type itself:
- It doesn't tell me what properties it has (
name
). - It doesn't tell me the types of those properties (
string
). - It doesn't tell me how to create a value matching this type.
In this case, I'd much prefer to see something like let foo: { name: string }
.
So my question is: How can I tell TypeScript to reduce an aliased type to its mere structure, discarding the name of the type alias used?
The strange thing is that this type alias preservation doesn't always happen:
let test: Uppercase<'foo'>;
Hovering over test
in this example shows me let test: "FOO"
, not let test: Capitalize<'foo'>
. So there seems to be some kind of heuristic at work that decides whether to preserve the type alias or not. I'd just like a way to control this choice myself.