Skip to content

selectionStart should not be nullable: TSJS-lib-generator regression in 2.8.x  #23094

@styfle

Description

@styfle

TypeScript Version: 2.8.1

Search Terms:
selectionStart, selectionEnd

Code

// Source code from https://github.com/styfle/copee
function fromElement(el: HTMLInputElement | HTMLTextAreaElement, preserveSelection?: boolean) {
    let start = 0;
    let end = 0;
    let success = false;

    if (preserveSelection) {
        start = el.selectionStart;
        end = el.selectionEnd;
    }

    el.select();

    try {
        success = document.execCommand('copy');
    } catch (err) {
        success = false;
    }

    if (preserveSelection) {
        el.setSelectionRange(start, end);
    }

    return success;
}

Expected behavior:
el.selectionStart and el.selectionEnd should return number

Actual behavior:
el.selectionStart and el.selectionEnd actually return number | null

Playground Link:
Playground

Related Issues:
#22381 , styfle/copee#21

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs More InfoThe issue still hasn't been fully clarified

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions