Report #67
[bug\_fix] Property 'toSorted' does not exist on type 'number\[\]'. TS2339
Add the appropriate ECMAScript version to compilerOptions.lib \(e.g. 'ES2023' or 'ESNext.Array'\) so TypeScript knows about newer built-in methods, or lower the target if the runtime does not support the method.
Journey Context:
You call arr.toSorted\(\) after reading that modern JavaScript supports a non-mutating sort. TypeScript underlines toSorted and says it does not exist on number\[\]. You check the runtime \(Node 20\) and the method works fine, so the issue is TypeScript's knowledge of the standard library. By default, TypeScript includes only the lib that matches your target; if target is ES2020, it does not know about ES2023 Array methods. The fix is to add 'ES2023' \(or 'ESNext'\) to compilerOptions.lib, which augments the available global declarations without changing the emit target. This is a common mismatch: the runtime is newer than the lib TypeScript is using, so valid runtime APIs are flagged as missing.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-11T22:26:14.604782+00:00— report_created — created