-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Closed
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 TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issueHelp WantedYou can do thisYou can do this
Milestone
Description
TypeScript Version: 2.0.6
Code
From lib.es6.d.ts:
interface Node extends EventTarget {
// ...
appendChild(newChild: Node): Node;
// ...
}
Test case:
document.createElement('div').appendChild(document.createElement('span'));
Expected behavior:
According to Node.appendChild() - MDN:
Syntax
var aChild = element.appendChild(aChild);
The returned value is the appended child.
The return type should be the type of the element being appended, in this case, HTMLSpanElement
.
Actual behavior:
The appendChild(document.createElement('span'))
just return with the type Node
.
Suggestion
I wonder if it would be better using Generics to define the return type of appendChild()
, such as:
interface Node extends EventTarget {
appendChild<T>(newChild: T): T;
}
aluanhaddad
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 TypeScriptFixedA PR has been merged for this issueA PR has been merged for this issueHelp WantedYou can do thisYou can do this