@@ -2,18 +2,18 @@ import { uniqBy } from 'lodash';
22import { IntrinsicNode } from './intrinsic' ;
33import { LiteralNode } from './literal' ;
44import { ExternalTypeNode } from './external' ;
5- import { TypeNode } from '../node' ;
5+ import { AnyType } from '../node' ;
66import { IntersectionNode } from './intersection' ;
77import { UnionNode } from './union' ;
88import { TypeParameterNode } from './typeParameter' ;
99
1010export function flattenTypes (
11- nodes : readonly TypeNode [ ] ,
11+ nodes : readonly AnyType [ ] ,
1212 nodeToProcess : typeof UnionNode | typeof IntersectionNode ,
13- ) : TypeNode [ ] {
14- let flatTypes : TypeNode [ ] = [ ] ;
13+ ) : AnyType [ ] {
14+ let flatTypes : AnyType [ ] = [ ] ;
1515 nodes . forEach ( ( node ) => {
16- if ( node instanceof nodeToProcess && ! node . name ) {
16+ if ( node instanceof nodeToProcess && ! node . typeName ) {
1717 flatTypes = flatTypes . concat ( flattenTypes ( node . types , nodeToProcess ) ) ;
1818 } else {
1919 flatTypes . push ( node ) ;
@@ -23,25 +23,29 @@ export function flattenTypes(
2323 return flatTypes ;
2424}
2525
26- export function deduplicateMemberTypes ( types : TypeNode [ ] ) : TypeNode [ ] {
26+ export function deduplicateMemberTypes ( types : AnyType [ ] ) : AnyType [ ] {
2727 return uniqBy ( types , ( x ) => {
2828 if ( x instanceof LiteralNode ) {
2929 return x . value ;
3030 }
3131
32- if ( x instanceof ExternalTypeNode || x instanceof TypeParameterNode ) {
32+ if ( x instanceof ExternalTypeNode ) {
33+ return x . typeName ;
34+ }
35+
36+ if ( x instanceof TypeParameterNode ) {
3337 return x . name ;
3438 }
3539
3640 if ( x instanceof IntrinsicNode ) {
37- return x . name ?? x . intrinsic ;
41+ return x . typeName ?? x . intrinsic ;
3842 }
3943
4044 return x ;
4145 } ) ;
4246}
4347
44- export function sortMemberTypes ( members : TypeNode [ ] ) {
48+ export function sortMemberTypes ( members : AnyType [ ] ) {
4549 // move undefined and null to the end
4650
4751 const nullIndex = members . findIndex ( ( x ) => x instanceof IntrinsicNode && x . intrinsic === 'null' ) ;
0 commit comments