Use modern JavaScript features and utility functions consistently for null/undefined checks. Prefer optional chaining (?.), nullish coalescing (??), and dedicated utility functions like isNil() over direct null checks or OR (||) operators.
Use modern JavaScript features and utility functions consistently for null/undefined checks. Prefer optional chaining (?.), nullish coalescing (??), and dedicated utility functions like isNil() over direct null checks or OR ( | ) operators. |
Key practices:
// Use if (pattern?.test(str))
2. Use nullish coalescing for default values:
```typescript
// Instead of
const ttlValueOrFactory = ttlMetadata || null;
// Use
const ttlValueOrFactory = ttlMetadata ?? null;
// Use import { isNil } from ‘@nestjs/common/utils’; if (isNil(value)) ```
This approach improves code readability, reduces potential null reference errors, and maintains consistency across the codebase. It leverages TypeScript’s type system and modern JavaScript features for better null safety.
Enter the URL of a public GitHub repository