class EditorState{
static createWithText(
text: string,
decorator?: ?DraftDecoratorType,
): EditorState {
return EditorState.createWithContent(
ContentState.createFromText(text),
decorator,
);
}
}
有人能解释一下这个代码的作用吗?
尤其是decorator?: ?DraftDecoratorType,
,它不是像if语句那样的ternery运算符吗?
这看起来像一个TypeScript函数定义,其中包含额外的键入信息。
它不是三元的,这里decorator?:
意味着decorator
是一个可选参数。
这不是三元表达式,而是流类型注释。
decorator?
是可选参数
可选参数将接受缺失、
undefined
或匹配的类型。但他们不会接受null
?DraftDecoratorType
可能是类型
可能类型接受所提供的类型以及
null
或undefined