在 TypeScript 中调用 class 方法时,class 名称后的问号 (?) 是什么意思?

What does question mark (?) after class name mean when calling class methods in TypeScript?

我有一个 TypeScript 代码片段,其中包含以下语句 row?.delete();

我想知道问号代表什么?

如果行为空会怎样?

谢谢!

此运算符称为可选链接。它所做的是首先检查该行是否已定义,然后尝试访问删除。

如果行为空,此 row?.delete() 将只是 return undefined.If 你在没有此运算符的情况下使用它,如 row.delete() 并且行为空,你将得到 Uncaught Type Error: Cannot read property 'row' of undefined.

有关更多详细信息和示例,您可以在此处查看 https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html