From 7c108f8d22cd41ed0227912d10c8cb5695a4b0c7 Mon Sep 17 00:00:00 2001 From: Shoaib Khan Date: Wed, 9 Sep 2026 22:26:41 -0400 Subject: [PATCH] Fix swapped charCodeAt/codePointAt JSDoc descriptions charCodeAt's doc said "Unicode value", which is ambiguous and actually describes codePointAt's behavior. codePointAt's doc led with "UTF-16 encoded code point", obscuring that it returns the full Unicode code point value (handling surrogate pairs), which is what actually distinguishes it from charCodeAt. charCodeAt now says it returns the UTF-16 code unit at the index; codePointAt now says it returns the Unicode code point value, per MDN and the issue discussion. Fixes #49561 Co-Authored-By: Claude Fable 5.1 --- tsc/internal/bundled/libs/lib.es2015.core.d.ts | 7 ++++--- tsc/internal/bundled/libs/lib.es5.d.ts | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/tsc/internal/bundled/libs/lib.es2015.core.d.ts b/tsc/internal/bundled/libs/lib.es2015.core.d.ts index e36b9fbdadd0c..d3f1eadf81ed7 100644 --- a/tsc/internal/bundled/libs/lib.es2015.core.d.ts +++ b/tsc/internal/bundled/libs/lib.es2015.core.d.ts @@ -399,9 +399,10 @@ interface RegExpConstructor { interface String { /** - * Returns a nonnegative integer Number less than 1114112 (0x110000) that is the code point - * value of the UTF-16 encoded code point starting at the string element at position pos in - * the String resulting from converting this object to a String. + * Returns a nonnegative integer Number less than 1114112 (0x110000) that is the Unicode + * code point value starting at the string element at position pos in the String resulting + * from converting this object to a String. Note that this is the code point starting at pos, + * not the pos-th code point of the string. * If there is no element at that position, the result is undefined. * If a valid UTF-16 surrogate pair does not begin at pos, the result is the code unit at pos. */ diff --git a/tsc/internal/bundled/libs/lib.es5.d.ts b/tsc/internal/bundled/libs/lib.es5.d.ts index e394111cb0e6c..4f86ffe9f1ff0 100644 --- a/tsc/internal/bundled/libs/lib.es5.d.ts +++ b/tsc/internal/bundled/libs/lib.es5.d.ts @@ -416,8 +416,8 @@ interface String { charAt(pos: number): string; /** - * Returns the Unicode value of the character at the specified location, or NaN if the index is out of bounds. - * @param index The zero-based index of the desired character. + * Returns the UTF-16 code unit at the specified index, or NaN if the index is out of bounds. + * @param index The zero-based index of the desired code unit. */ charCodeAt(index: number): number;