TYPE012infoPro

dom-selection-null-check

Accessing selectionStart/selectionEnd without null check

Applies to: JavaScript, TypeScript

Why this matters

selectionStart and selectionEnd return null for input types that don't support text selection (like number, date, color). Using these values in arithmetic or assignment without a null check causes TypeError in production. Always null-check or use the nullish coalescing operator (??).

Catch it before it ships

pip install stablestack # or: npx stablestackstablestack # scans your project, TYPE012 includedstablestack explain TYPE012

TYPE012 is part of the Pro rule set. See pricing — the free tier ships 24 checks with no signup.

False positive in your codebase? Suppress a single line with # noqa: TYPE012