typescript ?: 在打字稿中是什么意思?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23557030/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What does ?: mean in Typescript?
提问by Erik Z
I found the following in a TypeScript declaration file for Angular:
我在 Angular 的 TypeScript 声明文件中发现了以下内容:
interface IDirective{
compile?:
(templateElement: IAugmentedJQuery,
What does the ?:
after compile do?
什么是?:
编译后怎么办?
回答by Amadan
See: Walkthrough: Interfaces | TypeScript :: Describing Simple Types.
请参阅:演练:接口 | TypeScript :: 描述简单类型。
Basically, ?
marks the member as being optional in the interface.
基本上,?
在接口中将成员标记为可选。
(EDIT: As noted in comments, this is not restricted to interfaces.)
(编辑:如评论中所述,这不仅限于接口。)
回答by KarolDepka
In this case, the ?:
is not a single operator, but rather two operators:
在这种情况下,?:
不是单个运算符,而是两个运算符:
?
(optional),:
(specify type).
?
(可选的),:
(指定类型)。
In other languages/cases, ?:
would be the Elvis Operator.
在其他语言/情况下,?:
将是Elvis Operator。