microsoft / microsoft/TypeScript
NodeList is no more compatible with Array<Node>. Breaking change in 3.0
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
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.
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Finde die Dokumentation zu den Breaking Changes in TypeScript 3.0 und prüfe, wie Kompatibilitätsänderungen aufgeführt werden. Dokumentiere, dass die forEach-Signaturen von NodeList und Array inkompatibel wurden, einschließlich der betroffenen Version und des im Issue gezeigten Migrationskontexts. Als erledigt gilt die Aufgabe, wenn die Breaking Change eindeutig in der relevanten Liste enthalten ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- documentation
- Issue-Typ
- Dokumentation
- Schwierigkeit
- 2/5
- Geschätzter Aufwand
- 1-3 Stunden
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100