83 fs.readdirSync(dir).forEach(function (file) {
84 file = dir + path.sep + file;
85 const stat = fs.statSync(file);
86 if (stat && stat.isDirectory()) { 87 /* Recurse into a subdirectory */
88 results = results.concat(osWalk(file));
89 } else {
The optional chaining operator can be used to perform null checks before accessing a property, or calling a function.
Using &&
for this purpose is no longer required.
function getUsernameFromId(id: number): string | undefined {
const user = db.getUser(id)
return user && user.name
}
someFunc && someFunc()
// ^~~~ not necessary
maybeArray && maybeArray[index]
// ^~~~ not necessary
function getUsernameFromId(id: number): string | undefined {
const user = db.getUser(id)
return user?.name
}
someFunc?.()
maybeArray?.[index]