Skip to content

Docs of charCodeAt and codePointAt are flipped #49561

@Ciantic

Description

@Ciantic

Bug Report

Docs of charCodeAt and codePointAt are flipped. Described in MDN, the codePointAt returns Unicode code point, and charCodeAt returns UTF16 char code, however in JSDoc string of Typescript they are flipped.

How it is

/**
* 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.
* 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.
*/
codePointAt(pos: number): number | undefined;

TypeScript/lib/lib.es5.d.ts

Lines 404 to 408 in 89d05f7

/**
* Returns the Unicode value of the character at the specified location.
* @param index The zero-based index of the desired character. If there is no character at the specified index, NaN is returned.
*/
charCodeAt(index: number): number;

How it should be

The codePointAt() method returns a non-negative integer that is the Unicode code point value at the given position. Note that this function does not give the nth code point in a string, but the code point starting at the specified string index. Docs

The charCodeAt() method returns an integer between 0 and 65535 representing the UTF-16 code unit at the given index. Docs

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions