我最近翻阅了 https://github.com/ory/editor/blob/master/packages/ui/src/Trash/index.js#L89
发现了一种我不理解的论点。 这是完整的代码:
const types = ({ editor }: { editor: Editor }) => {
const plugins = [
...Object.keys(editor.plugins.plugins.layout),
...Object.keys(editor.plugins.plugins.content)
].map(
(p: string) =>
editor.plugins.plugins.content[p].name ||
editor.plugins.plugins.layout[p].name
)
if (editor.plugins.hasNativePlugin()) {
plugins.push(editor.plugins.getNativePlugin()().name)
}
return plugins
}
论点是什么意思?叫什么?
答案 0 :(得分:1)
这意味着函数将接收一个带有Editor属性的对象,并且具有Editor类型。
有关更多信息,您可以检查https://flow.org/en/
答案 1 :(得分:1)
这里有2个部分。
editor
属性{ editor }
没有类型定义,它看起来像这样。如果知道,您只需要一个传递对象的编辑器,就可以对其进行销毁
// Passing and working with the whole object
const fn1 = ( obj ) => {
const editor = obj.editor;
console.log( editor );
};
// Destructing the object and only use the editor property
// Basically the same as fn1 without the whole obj.
const fn2 = ( { editor } ) => {
console.log( editor );
};
const obj = {
editor: 'Editor',
};
fn1( obj );
fn2( obj );