0%

typescript-coding-standard

Syntax

User optional chaining operator ? instead of &&

1
2
3
4
5
6
7
8
9
10
const user = {
name: 'John',
address: {
city: 'New York',
state: 'NY'
}
};

const city = user && user.address && user.address.city; // old way
const city = user?.address?.city; // new way

这种方式确实简单很多,但是处理Unit Test可能会麻烦一些。

Use nullish coalescing operator ?? instead of ||

1
2
const name = user.name || 'Guest'; // old way
const name = user.name ?? 'Guest'; // new way