(property, prefix)
| 16 | } |
| 17 | |
| 18 | function propertyToDoc(property, prefix) { |
| 19 | let type; |
| 20 | let name; |
| 21 | |
| 22 | if (property.type === 'ObjectTypeProperty') { |
| 23 | // flow |
| 24 | type = typeAnnotation(property.value); |
| 25 | } else if (property.type === 'TSPropertySignature') { |
| 26 | // typescript |
| 27 | type = typeAnnotation(property.typeAnnotation); |
| 28 | } else if (property.type === 'TSMethodSignature') { |
| 29 | // typescript |
| 30 | type = typeAnnotation(property); |
| 31 | } |
| 32 | |
| 33 | if (property.key) { |
| 34 | name = property.key.name || property.key.value; |
| 35 | } |
| 36 | |
| 37 | // Special handling for { ...$Exact<Type> } |
| 38 | if (isObjectSpreadAndExactUtilTypeProperty(property)) { |
| 39 | name = property.argument.id.name; |
| 40 | type = { |
| 41 | type: 'NameExpression', |
| 42 | name: property.argument.typeParameters.params[0].id.name |
| 43 | }; |
| 44 | } |
| 45 | |
| 46 | if (property.optional) { |
| 47 | type = { |
| 48 | type: 'OptionalType', |
| 49 | expression: type |
| 50 | }; |
| 51 | } |
| 52 | return { |
| 53 | title: 'property', |
| 54 | name: prefixedName(name, prefix), |
| 55 | lineNumber: property.loc.start.line, |
| 56 | type |
| 57 | }; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Infers properties of TypeAlias objects (Flow or TypeScript type definitions) |
no test coverage detected