microsoft / microsoft/TypeScript

Variable aliasing this should be treated the same as this

Aperta
#36,618 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.3k
Merge medio
2g 4h
PR unite (30g)
132

Descrizione

Search Terms

this alias

Suggestion

If I do const me = this; then me should be treated the same as this especially since it's a constant and cannot be updated to another value

Use Cases

I'm using --allowJs and --checkJs. Right now TypeScript makes us do this:

	constructor(chart, datasetIndex) {
		this.chart = chart;
		this._ctx = chart.ctx;
		this.index = datasetIndex;
		this._cachedAnimations = {};
		this._cachedDataOpts = {};
		this._cachedMeta = this.getMeta();
		this._type = this._cachedMeta.type;
		this._config = undefined;
		this._parsing = false;
		this._data = undefined;
		this._dataCopy = undefined;
		this._objectData = undefined;
		this._labels = undefined;
		this._scaleStacked = {};

		this.initialize();
	}

Examples

I would like to be able to do this:

	constructor(chart, datasetIndex) {
		const me = this;
		me.chart = chart;
		me._ctx = chart.ctx;
		me.index = datasetIndex;
		me._cachedAnimations = {};
		me._cachedDataOpts = {};
		me._cachedMeta = this.getMeta();
		me._type = this._cachedMeta.type;
		me._config = undefined;
		me._parsing = false;
		me._data = undefined;
		me._dataCopy = undefined;
		me._objectData = undefined;
		me._labels = undefined;
		me._scaleStacked = {};

		me.initialize();
	}

This would make our transition to TypeScript much easier since our code follows this pattern throughout the codebase. It would also result in a smaller file size, which is why we'd adopted this pattern.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

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

La issue non indica alcun file sorgente, test o punto di ingresso. Inizia riproducendo gli esempi con --allowJs e --checkJs, quindi esamina come viene attualmente trattato un alias const di this. Il lavoro è completato quando l’alias riceve lo stesso comportamento di controllo di this senza modificare il JavaScript emesso.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.