Skip to content

Incorrect "setSelectionRange()" type declarations #20419

@mariusschulz

Description

@mariusschulz

lib.dom.d.ts currently has two different type declarations for the setSelectionRange() API for HTMLInputElement and HTMLTextAreaElement.

For HTMLInputElement (permalink):

setSelectionRange(start?: number, end?: number, direction?: string): void;

For HTMLTextAreaElement (permalink):

setSelectionRange(start: number, end: number): void;

However, both are wrong, if I'm not mistaken. According to MDN, the correct type declaration would be the following:

setSelectionRange(start: number, end: number, direction?: "forward" | "backward" | "none"): void;

Note that neither start nor end are optional. I also added a union of string literal types to type the (optional) direction parameter more precisely.

Metadata

Metadata

Assignees

Labels

Breaking ChangeWould introduce errors in existing codeBugA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptFixedA PR has been merged for this issueHelp WantedYou can do this

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions