microsoft / microsoft/TypeScript

Inconsistent assignment analysis for async arrow IIFE's regarding class property declarations (sugar vs constructor assigning)

Aperta
#38,929 1 commento 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Domain: check: Control Flow
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

TypeScript Version: 4.0.0-dev.202000519

Search Terms: async IIFE Property is used before being assigned class declaration

Code

This works fine:

class MyClass {
	public foo = 0;

	constructor() {
		(async () => this.foo + 5)();
	}
}

This, on the other hand, errors:

class MyClass {
	public foo: number;

	constructor() {
		this.foo = 0;
		(async () => this.foo + 5)(); // errors?
	}
}

These two code snippets should be treated the same because the first snippet is sugar for the second.

Expected behavior: (async () => this.foo + 5)() should not have the error "Property 'foo' is used before being assigned."

Actual behavior: It errors

Playground Link: Here

Related Issues:

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia riproducendo i due esempi di classe nel TypeScript Playground collegato e confronta l’analisi delle assegnazioni per le forme class-property e constructor-assignment. Esamina la gestione delle async arrow IIFEs e verifica che l’errore segnalato "used before being assigned" sia assente nel caso constructor-assignment, mentre il comportamento esistente rimanga corretto.

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.