33 fs.readdirSync(dir).forEach(function (file) {
34 file = dir + path.sep + file;
35 const stat = fs.statSync(file);
36 if (stat && stat.isDirectory()) { 37 /* Recurse into a subdirectory */
38 results = results.concat(osWalk(file));
39 } 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]