recordRef: { type: Object, required: true },
interface: { type: Object, required: true },
alias: { type: Array, required: true },
+ method: { type: Function, required: true },
union: { type: [String, Number], required: true },
literalUnion: { type: [String, String], required: true },
literalUnionMixed: { type: [String, Number, Boolean], required: true },
recordRef: Record<string, null>
interface: Test
alias: Alias
+ method(): void
union: string | number
literalUnion: 'foo' | 'bar'
recordRef: Record<string, null>
interface: Test
alias: Alias
+ method(): void
union: string | number
literalUnion: 'foo' | 'bar'
expect(content).toMatch(`recordRef: { type: Object, required: true }`)
expect(content).toMatch(`interface: { type: Object, required: true }`)
expect(content).toMatch(`alias: { type: Array, required: true }`)
+ expect(content).toMatch(`method: { type: Function, required: true }`)
expect(content).toMatch(
`union: { type: [String, Number], required: true }`
)
recordRef: BindingTypes.PROPS,
interface: BindingTypes.PROPS,
alias: BindingTypes.PROPS,
+ method: BindingTypes.PROPS,
union: BindingTypes.PROPS,
literalUnion: BindingTypes.PROPS,
literalUnionMixed: BindingTypes.PROPS,
) {
const members = node.type === 'TSTypeLiteral' ? node.members : node.body
for (const m of members) {
- if (m.type === 'TSPropertySignature' && m.key.type === 'Identifier') {
+ if (
+ (m.type === 'TSPropertySignature' || m.type === 'TSMethodSignature') &&
+ m.key.type === 'Identifier'
+ ) {
+ let type
+ if (__DEV__) {
+ if (m.type === 'TSMethodSignature') {
+ type = ['Function']
+ } else if (m.typeAnnotation) {
+ type = inferRuntimeType(
+ m.typeAnnotation.typeAnnotation,
+ declaredTypes
+ )
+ }
+ }
props[m.key.name] = {
key: m.key.name,
required: !m.optional,
- type:
- __DEV__ && m.typeAnnotation
- ? inferRuntimeType(m.typeAnnotation.typeAnnotation, declaredTypes)
- : [`null`]
+ type: type || [`null`]
}
}
}