Severity: error
Category: null-safety
Stage: Stage 0 (prototype)
Description
All types in SJS are non-nullable by default. Assigning null or undefined to a type T without
opting into nullability (the T? suffix) is a type error.
Example
// ✗ error
let name: string = null // SJS-E001
function greet(user: string) {
return `Hello, ${user}`
}
greet(undefined) // SJS-E001Fix
Append ? to make the type nullable, then narrow before use:
// ✓ correct
let name: string? = null
function greet(user: string?): string {
if (user === null) return "Hello, stranger"
return `Hello, ${user}`
}Or, if the value must always be present, ensure the assignment can never be null.
Related codes
SJS-E003— property access on possibly-null valueSJS-E011— non-null assertion (!) is banned