Tilde Range (~) — Patch-Level Updates Only
Understand the tilde (~) range in semantic versioning. Learn how ~1.2.3 allows only patch updates (>=1.2.3 <1.3.0) for conservative dependency management.
Tilde Ranges
Detailed Explanation
Understanding the Tilde Range (~)
The tilde range is the conservative alternative to the caret range. It allows only patch-level updates, meaning bug fixes but no new features.
How the Tilde Works
~MAJOR.MINOR.PATCH allows changes to the patch version only:
| Range | Expanded | Allowed |
|---|---|---|
~1.2.3 |
>=1.2.3 <1.3.0 |
1.2.3, 1.2.4, 1.2.99 |
~1.2 |
>=1.2.0 <1.3.0 |
Same as above |
~1 |
>=1.0.0 <2.0.0 |
All 1.x (like ^1) |
~0.2.3 |
>=0.2.3 <0.3.0 |
0.2.3, 0.2.4, 0.2.99 |
Tilde vs Caret
The key difference is in how much flexibility each allows:
| Version | Caret (^) | Tilde (~) |
|---|---|---|
1.2.3 |
<2.0.0 |
<1.3.0 |
0.2.3 |
<0.3.0 |
<0.3.0 |
0.0.3 |
<0.0.4 |
<0.1.0 |
Notice that for 0.2.3, the tilde and caret produce the same result. They diverge only for versions >=1.0.0.
When to Use Tilde
Choose the tilde when:
- You have been burned by a minor version update breaking your code
- The dependency is critical and stability matters more than features
- You are pinning a specific feature set and only want bug fixes
{
"dependencies": {
"critical-lib": "~2.4.0"
}
}
This accepts 2.4.0 through 2.4.x but rejects 2.5.0.
Use Case
Used in production environments where stability is paramount, or when a minor version update of a dependency has previously introduced regressions.