【发布时间】:2021-04-07 19:34:18
【问题描述】:
如果有一个 TypeScript 函数f: A => B。但是我在我的应用程序中输入可能是未定义的,所以我总是必须写,比如说,const b?: B = a && f(a);。
我可以更改函数以在函数中包含检查吗(即,类似于
(a: A | undefined) => B | undefined = (a => a && …),但是如果 a 不能未定义,则返回类型不包含 undefined,这样如果 a 不能未定义,我可以写 const b: B = f(a),如果 a 可以,我可以写 const b?: B = f(a)?
【问题讨论】:
标签: typescript undefined typescript-generics