microsoft / microsoft/TypeScript

Strict Reflect.apply Reflect.construct and Function.prototype.apply/call/bind

Aperta
#33,889 6 commenti 4 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

Reflect.apply
Reflect.construct
Function.prototype.apply
Function.prototype.call
Function.prototype.bind

Suggestion

These functions should not return any.

Related:
https://github.com/microsoft/TypeScript/issues/212
https://github.com/microsoft/TypeScript/pull/27028

Use Cases

function getString() {
  return 'string'
}

class ClassA {}

Reflect.apply(getString, null, []) // expected string but got any
Reflect.construct(ClassA, []) // expected ClassA but got any
Function.prototype.apply.call(getString, undefined) // expected string but got any
Function.prototype.call.call(getString, undefined) // expected string but got any
Function.prototype.bind.call(getString, undefined)() // expected string but got any

Examples

Reflect:

// old
function apply(target: Function, thisArgument: any, argumentsList: ArrayLike<any>): any;

// new
function apply<T>(target: (...args: any) => T, thisArgument: any, argumentsList: ArrayLike<any>): T;

// old
function construct(target: Function, argumentsList: ArrayLike<any>, newTarget?: any): any;

// new
function construct<T>(target: new (...args: any) => T, argumentsList: ArrayLike<any>, newTarget?: any): T;

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
    👆 Add a new compiler option
  • 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

Inizia leggendo le dichiarazioni attuali e i test di verifica dei tipi correlati a Reflect.apply, Reflect.construct e Function.prototype.apply/call/bind. Confrontali con i tipi restituiti attesi nell'issue e verifica che gli esempi elencati inferiscano string e ClassA invece di any.

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

Valutazione

Stack tecnologico
javascript, typescript
Ambito
compilers
Tipo di issue
Funzionalità
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.