TS18047
Value is possibly null
'value' is possibly 'null'.The compiler’s own words. Not translated — this is the string you pasted into a search box.
A nullable value is used as though the `null` branch had already been ruled out.
Reproduction
function upper(value: string | null) { return value.toUpperCase() }
The build asserts this emits exactly this code.
Why the compiler says this
With strict null checking, `string | null` is two real possibilities. Methods of `string` are safe only after control flow proves that the current value belongs to the string branch.
Fixes
- 01
function upper(value: string | null) { if (value === null) return '' return value.toUpperCase() }
Guard the null case and choose the behavior your domain requires.
- 02
function upper(value: string | null) { return value?.toUpperCase() ?? '' }
Use optional chaining with an explicit fallback for a compact transformation.
Takeaway
Narrow nullable values where you use them; a non-null assertion merely moves the risk to runtime.
