( program: ts.Program, type: ts.Type )
| 38 | } |
| 39 | |
| 40 | export 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 | |
| 73 | export function mapPropertyTypesToSchemaDescriptor(propTypes: { |
| 74 | [key: string]: ts.Type |
no test coverage detected