TypeScript !. & ?. operators All In One
TypeScript !. & ?. operators All In One
TypeScript Bang! (non-null assertion operator) !.
postfix
operator /非空断言
操作符
const columns = [{width: 100}];
const widthColumnCount = columns!.filter(({ width }) => !width).length;
/*
"use strict";
const columns = [{ width: 100 }];
const widthColumnCount = columns.filter(({ width }) => !width).length;
*/
?.
可选链
操作符
const columns = [{width: 100}];
const widthColumnCount = columns?.filter(({ width }) => !width).length;
/*
"use strict";
const columns = [{ width: 100 }];
const widthColumnCount = columns === null || columns === void 0 ? void 0 : columns.filter(({ width }) => !width).length;
*/
demos
typescript playgorund
https://www.typescriptlang.org/play
JavaScript Bang!
prefix
operator
- 类型取反
- 类型转换成布尔逻辑值
!false
// true
!!false
// false
!0
// true
!!0
// false
refs
https://dev.to/pssingh21/safe-navigation-operator-bang-bang-bang-192j
https://www.cnblogs.com/xgqfrms/p/18222160
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/15681295.html
未经授权禁止转载,违者必究!