Skip to content

'innerText' should not be nullable in most of Node's derived types #10315

@DanielRosenwasser

Description

@DanielRosenwasser

Compile the following with --strictNullChecks with the DOM available.

const foo = document.createElement("div");
const s: string = foo.textContent;

Expected: No error
Actual: Type 'string | null' is not assignable to type 'string'.

From https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent:

  • textContent returns null if the element is a document, a document type, or a notation. [...]
  • If the node is a CDATA section, a comment, a processing instruction, or a text node, textContent returns the text inside this node (the nodeValue).
  • For other node types, textContent returns the concatenation of the textContent attribute value of every child node, excluding comments and processing instruction nodes. This is an empty string if the node has no children.

Proposed fix: textContent will be defined as nullable inNode, but overridden asstring` in most of its descendants.

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