File tree Expand file tree Collapse file tree 3 files changed +58
-1
lines changed Expand file tree Collapse file tree 3 files changed +58
-1
lines changed Original file line number Diff line number Diff line change @@ -30,9 +30,19 @@ export function resolveUnionType(
3030 memberTypes = type . origin . types ;
3131 }
3232
33+ // If there's no provided type node or it's is not a union,
34+ // We check if the type declaration is an alias.
35+ // If so, it can point to the original union type.
36+ //
37+ // For example:
38+ // function f(x: Params) {}
39+ // type Params = SomeType | SomeOtherType;
40+ //
41+ // In this case `typeNode` will be set to the type reference of the function parameter,
42+ // so we extract the needed union definition.
3343 const typeAliasDeclaration = type . aliasSymbol ?. declarations ?. [ 0 ] ;
34-
3544 if (
45+ ( ! typeNode || ! ts . isUnionTypeNode ( typeNode ) ) &&
3646 typeAliasDeclaration &&
3747 ts . isTypeAliasDeclaration ( typeAliasDeclaration ) &&
3848 ts . isUnionTypeNode ( typeAliasDeclaration . type )
Original file line number Diff line number Diff line change 11export function f ( x : Params ) { }
22
3+ export interface Props {
4+ x : Params ;
5+ }
6+
37type Params = Alias | 0 ;
48
59type SomeType = 1 | 2 ;
Original file line number Diff line number Diff line change 5151 }
5252 ]
5353 }
54+ },
55+ {
56+ "name" : " Props" ,
57+ "type" : {
58+ "kind" : " object" ,
59+ "typeName" : {
60+ "name" : " Props"
61+ },
62+ "properties" : [
63+ {
64+ "name" : " x" ,
65+ "type" : {
66+ "kind" : " union" ,
67+ "typeName" : {
68+ "name" : " Params"
69+ },
70+ "types" : [
71+ {
72+ "kind" : " literal" ,
73+ "value" : 0
74+ },
75+ {
76+ "kind" : " union" ,
77+ "typeName" : {
78+ "name" : " Alias"
79+ },
80+ "types" : [
81+ {
82+ "kind" : " literal" ,
83+ "value" : 1
84+ },
85+ {
86+ "kind" : " literal" ,
87+ "value" : 2
88+ }
89+ ]
90+ }
91+ ]
92+ },
93+ "optional" : false
94+ }
95+ ]
96+ }
5497 }
5598 ]
5699}
You can’t perform that action at this time.
0 commit comments