param之前或之后的流式问号? [英] flow type question mark before or after param?

查看:117
本文介绍了param之前或之后的流式问号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以解释之间的区别:

Can someone explain the difference between:

function foo(bar: ?string) {
  console.log(bar);
}

和:

function foo(bar?: string) {
  console.log(bar);
}

何时使用其中一个?

推荐答案

基本上

bar: ?string

接受字符串,无效或无效:

accepts a string, null or void:

foo("test");
foo(null);
foo()

虽然

bar?: string

只接受一个字符串或无效:

Accepts only a string or void:

foo("test");
foo();

由于传递null而不是字符串有点无意义,因此它们之间没有真正的生命差异。

As passing null instead of a string is somewhat senseless, theres no real life difference between them.

这篇关于param之前或之后的流式问号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆