import type * as ts from 'typescript' ; import { Scope } from '../../scope/scope' ; import { core } from '../../core/core' ; import { GetMockPropertiesFromDeclarations } from '../mock/mockProperties' ; import { GetTypes } from '../type/type' ; import { createNodeArray , createProperty , } from '../../../typescriptFactory/typescriptFactory' ; export function GetMappedDescriptor ( node , scope ) { const typeParameter = node . typeParameter . constraint ; const parameters = [ ] ; if ( typeParameter ) { parameters . push ( typeParameter ) ; } const types = GetTypes ( createNodeArray ( parameters ) , scope ) ; const properties = types . reduce ( ( acc , possibleType ) => { if ( core . ts . isLiteralTypeNode ( possibleType ) ) { const property = createProperty ( ( possibleType . literal as ts . StringLiteral ) . text , node . type ) ; acc . push ( property ) ; return acc ; } const type = core . typeChecker . getTypeAtLocation ( possibleType ) ; const propertiesDeclaration = core . typeChecker . getPropertiesOfType ( type ) . map ( ( symbol ) => createProperty ( symbol . name , node . type ) ) ; acc = acc . concat ( propertiesDeclaration ) ; return acc ; } , [ ] ) ; return GetMockPropertiesFromDeclarations ( properties , [ ] , scope ) ; }