microsoft / microsoft/TypeScript
NodeList is no more compatible with Array<Node>. Breaking change in 3.0
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 132
Description
TypeScript Version: Version 3.0.3
Code
I didn't find any mentioning to this breaking change.
This code used to compile in 2.9.2:
/**
* Array based implementation of NodeList
*/
class JSArrayNodeList extends Array<Node> implements NodeList {
constructor(items?: Array<Node>) {
if (items) {
super(...items);
} else {
super();
}
}
public item(index: number): Node {
return this[index];
}
public copy(): JSArrayNodeList {
return new JSArrayNodeList(this);
}
}
In 3.0 forEach method of NodeList and Array became incompatible.
Due to this changeset: https://github.com/Microsoft/TypeScript/commit/7a7d04e126fb7c1c6074ef26657eddb0f32e4003
A solution was to add explicit forEach which delegates call to super:
/**
* Array based implementation of NodeList
*/
class JSArrayNodeList extends Array<Node> implements NodeList {
constructor(items?: Array<Node>) {
if (items) {
super(...items);
} else {
super();
}
}
public forEach(
callbackfn: ((value: Node, index: number, array: Node[]) => void) | ((value: Node, key: number, parent: NodeList) => void),
thisArg?: any): void {
// Just call Array.forEach
Array.prototype.forEach.call(thisArg, this, callbackfn);
}
public item(index: number): Node {
return this[index];
}
public copy(): JSArrayNodeList {
return new JSArrayNodeList(this);
}
}
Expected behavior:
Documentation in breaking change list.
Actual behavior:
No information about breaking change.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Locate the TypeScript 3.0 breaking changes documentation and review how compatibility changes are listed. Document that NodeList and Array forEach signatures became incompatible, including the affected version and the migration context shown in the issue. Done means the breaking change is clearly included in the relevant list.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100