-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Open
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisYou can do this
Milestone
Description
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
returnsnull
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 thetextContent
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 in
Node, but overridden as
string` in most of its descendants.
zanona, ExE-Boss, maranomynet and lionel-rowe
Metadata
Metadata
Assignees
Labels
BugA bug in TypeScriptA bug in TypeScriptDomain: lib.d.tsThe issue relates to the different libraries shipped with TypeScriptThe issue relates to the different libraries shipped with TypeScriptHelp WantedYou can do thisYou can do this