Skip to content

caretRangeFromPoint return type should be Range | null #1072

@melink14

Description

@melink14

caretRangeFromPoint Update Request

Configuration Check

My compilation target is ES2020 and my lib is caretRangeFromPoint.

Missing / Incorrect Definition

caretRangeFromPoint is currently defined as:

caretRangeFromPoint(x: number, y: number): Range;

but should be

caretRangeFromPoint(x: number, y: number): Range | null;

Sample Code

// Calculate range and friends here after we've made our fake textarea/input divs.
range = document.caretRangeFromPoint(ev.clientX, ev.clientY);
const startNode = range.startContainer;

This code should have a type error but currently doesn't since library doens't show return type as nullable. This happens quite often in the wild.

Documentation Link

https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint also shows null as possible return type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions