microsoft / microsoft/TypeScript
Class with 'private [Symbol.iterator]' is iterable outside of the class body
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.4k
- Ø Merge
- 1 T. 19 Std.
- Gemergte PRs (30 T.)
- 117
Beschreibung
TypeScript Version: 4.2.0-dev.20210103, seems to be a regression in 3.6, probably introduced by strictly typed generators (cc @rbuckton)
Search Terms: iteration, private
Expected behavior:
Errors like in v3.5:
Type 'C' is not assignable to type 'Iterable<string>'.
Property '[Symbol.iterator]' is private in type 'C' but not in type 'Iterable<string>'.
Type 'D' is not assignable to type 'Iterable<string>'.
Types of property '[Symbol.iterator]' are incompatible.
Type '() => D' is not assignable to type '() => Iterator<string>'.
Type 'D' is not assignable to type 'Iterator<string>'.
Property 'next' is private in type 'D' but not in type 'Iterator<string>'.
Actual behavior:
No error on iteration inside and outside of the class body.
Related Issues: #42051 and #42104
Code
class C {
private [Symbol.iterator]() {
return this;
}
public next() {
return {value: 'a', done: false};
}
}
class D {
public [Symbol.iterator]() {
return this;
}
private next() {
return {value: 'a', done: false};
}
}
function fn() {
for (const _ of new C()) {
}
for (const _ of new D()) {}
}
Compiler Options
{
"compilerOptions": {
"noImplicitAny": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"strictPropertyInitialization": true,
"strictBindCallApply": true,
"noImplicitThis": true,
"noImplicitReturns": true,
"alwaysStrict": true,
"esModuleInterop": true,
"declaration": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": 2,
"target": "ES2017",
"jsx": "React",
"module": "ESNext"
}
}
Playground Link: Provided
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
Beginne mit der bereitgestellten Playground-Reproduktion und vergleiche ihr Verhalten unter TypeScript 4.2-dev mit dem gemeldeten Verhalten unter 3.5; verwende die verwandten Issues #42051 und #42104 als Kontext. Verfolge, wie der Compiler private [Symbol.iterator]- und private next-Mitglieder behandelt; abgeschlossen ist die Aufgabe, wenn die ungültigen Iterationen die erwarteten Zuweisbarkeitsfehler erzeugen.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Klar beschrieben
- Anfängerfreundlichkeit
- 35/100