我在阅读vue/src/core/components/keep-alive.js代码的过程中,不是很理解类似于type VNodeCache = { [key: string]: ?VNode }
和getComponentName (opts: ?VNodeComponentOptions): ?string
这样的变量定义,想具体请教下这是用了什么工具包,有什么样的语法规则,以便更好的理解代码要表达的意思,十分感激。
(以下是较为完整的代码片段)
/* @flow */
import { isRegExp, remove } from 'shared/util'
import { getFirstComponentChild } from 'core/vdom/helpers/index'
type VNodeCache = { [key: string]: ?VNode };
function getComponentName (opts: ?VNodeComponentOptions): ?string {
return opts && (opts.Ctor.options.name || opts.tag)
}
function matches (pattern: string | RegExp | Array<string>, name: string): boolean {
if (Array.isArray(pattern)) {
return pattern.indexOf(name) > -1
} else if (typeof pattern === 'string') {
return pattern.split(',').indexOf(name) > -1
} else if (isRegExp(pattern)) {
return pattern.test(name)
}
/* istanbul ignore next */
return false
}
看下flow
官网