microsoft / microsoft/TypeScript
Class with 'private [Symbol.iterator]' is iterable outside of the class body
Nessuno ha ancora preso questa issue.
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.4k
- Merge medio
- 1g 19h
- PR unite (30g)
- 117
Descrizione
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
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia con la riproduzione fornita in Playground e confronta il suo comportamento con TypeScript 4.2-dev con quello segnalato in 3.5; usa le issue correlate #42051 e #42104 come contesto. Traccia la gestione da parte del compilatore dei membri privati [Symbol.iterator] e next; il lavoro è completato quando le iterazioni non valide producono gli errori di assegnabilità previsti.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 35/100