Non-Null Assertion Without Null Check
Description
The non-null assertion operator (!) bypasses null/undefined checks at compile time without runtime safety, causing crashes when values are unexpectedly null.
What Shoulder detects
How to fix
Use explicit null checks or optional chaining instead of non-null assertions.
```typescript
function getUserEmail(userId: string) {
const user = users.find(u => u.id === userId);
if (!user) {
throw new Error('User not found');
}
return user.email;
}
```
Learn more: https://shoulder.dev/learn/typescript/cwe-476/non-null-assertion
Applies to
Languages
Frameworks
express
fastify
nestjs
next
References
Scan for this issue
Detect with Shoulder CLI
npx @shoulderdev/cli trust --rule=typescript-non-null-assertion .