import type * as ts from 'typescript' ; import { Scope } from '../../scope/scope' ; import { core } from '../../core/core' ; import { GetDescriptor } from '../descriptor' ; import { GetTypes } from '../type/type' ; import { GetUndefinedDescriptor } from '../undefined/undefined' ; export function GetUnionDescriptor ( node , scope ) { const findNodes = GetTypes ( node . types , scope ) ; if ( scope . hydrated ) { const removeUndefinedNodes = findNodes . filter ( ( typeNode ) => ! isNotDefinedType ( typeNode ) ) ; if ( removeUndefinedNodes . length ) { return GetDescriptor ( removeUndefinedNodes [ 0 ] , scope ) ; } return GetUndefinedDescriptor ( ) ; } const notDefinedType = findNodes . filter ( ( typeNode ) => isNotDefinedType ( typeNode ) ) ; if ( notDefinedType . length ) { return GetUndefinedDescriptor ( ) ; } return GetDescriptor ( node . types [ 0 ] , scope ) ; } function isNotDefinedType ( typeNode ) { return ( typeNode . kind === core . ts . SyntaxKind . VoidKeyword || typeNode . kind === core . ts . SyntaxKind . UndefinedKeyword ) ; }