TypeScript Version: 3.5.2
Search Terms: indexed access lookup types type alias naming
Code
Given:
typeMyUnion=1|2|3;// Hover thistypeMyObject={value: MyUnion};If I hover over MyObject, I see { value: MyUnion; }.
However, given:
typeMyRecord={Foo: 1;Bar: 2;Baz: 3;}typeMyUnion=MyRecord[keyofMyRecord];// Hover thistypeMyObject={value: MyUnion};If I hover over MyObject, I see { value: 1 | 2 | 3; }.
I would expect the same behaviour as we see in my first example ({ value: MyUnion; }). The name of the type alias, MyUnion, should be preserved and its usage/reference inside of MyObject should be shown.
To give some context on my real world use case for this: I am using Unionize to create tagged unions (to avoid boilerplate for constructors, matchers, and type predicates). However, because of the issue described above, the types become very difficult to inspect/read: pelotom/unionize#60.
Under the hood, Unionize does something like this:
typeFoo={foo: number};typeBar={bar: number};typeBaz={baz: number};typeMyUnionRecord={Foo: Foo;Bar: Bar;Baz: Baz;};typeMyUnionTaggedRecord={[KinkeyofMyUnionRecord]: {tag: K;value: MyUnionRecord[K]}};typeMyUnion=MyUnionTaggedRecord[keyofMyUnionTaggedRecord];// Hover thistypeMyObject={value: MyUnion};If we hover over MyObject here, we see:
{
value: {
tag: "Foo";
value: Foo;}|{
tag: "Bar";
value: Bar;}|{
tag: "Baz";
value: Baz;};}… when we really want to see { value: MyUnion }.
As I demonstrated in pelotom/unionize#60, this scales really badly, e.g. when nesting unions.
TypeScript Version: 3.5.2
Search Terms: indexed access lookup types type alias naming
Code
Given:
If I hover over
MyObject, I see{ value: MyUnion; }.However, given:
If I hover over
MyObject, I see{ value: 1 | 2 | 3; }.I would expect the same behaviour as we see in my first example (
{ value: MyUnion; }). The name of the type alias,MyUnion, should be preserved and its usage/reference inside ofMyObjectshould be shown.To give some context on my real world use case for this: I am using Unionize to create tagged unions (to avoid boilerplate for constructors, matchers, and type predicates). However, because of the issue described above, the types become very difficult to inspect/read: pelotom/unionize#60.
Under the hood, Unionize does something like this:
If we hover over
MyObjecthere, we see:… when we really want to see
{ value: MyUnion }.As I demonstrated in pelotom/unionize#60, this scales really badly, e.g. when nesting unions.