MCPcopy Create free account
hub / github.com/andywer/postguard / resolvePropertyTypes

Function resolvePropertyTypes

src/typescript/objectish.ts:40–71  ·  view source on GitHub ↗
(
  program: ts.Program,
  type: ts.Type
)

Source from the content-addressed store, hash-verified

38}
39
40export function resolvePropertyTypes(
41 program: ts.Program,
42 type: ts.Type
43): { [key: string]: ts.Type } | null {
44 if (type.isIntersection()) {
45 return type.types.reduce<{ [key: string]: ts.Type }>(
46 // TODO: Don't just override previous property type
47 (reduced, subType) => ({
48 ...reduced,
49 ...resolvePropertyTypes(program, subType)
50 }),
51 {}
52 )
53 }
54
55 if (!isObjectType(type)) return null
56
57 const inheritedTypes: ts.BaseType[] =
58 type.objectFlags & ts.ObjectFlags.Interface
59 ? (type as ts.InterfaceType).getBaseTypes() || []
60 : []
61
62 const inheritedObjectTypes = inheritedTypes.filter(isObjectType) as ts.ObjectType[]
63
64 return [...inheritedObjectTypes, type].reduce(
65 (propertiesObject, someType) => ({
66 ...propertiesObject,
67 ...getObjectTypeProperties(program, someType)
68 }),
69 {}
70 )
71}
72
73export function mapPropertyTypesToSchemaDescriptor(propTypes: {
74 [key: string]: ts.Type

Callers 2

Calls 2

isObjectTypeFunction · 0.85
getObjectTypePropertiesFunction · 0.85

Tested by

no test coverage detected