microsoft / microsoft/TypeScript

Never returning functions should disable getter return requirement

Aperta
#52,214 1 commento 3 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Awaiting More Feedback Suggestion
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

Suggestion

declare const error: () => never;
const o = { get p() { error(); } };

Produces the error A 'get' accessor must return a value.(2378). Throwing an error directly would not. I feel similar to https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#better-support-for-never-returning-functions, a never-returning-function should have the same effect.

Afaik "control flow analysis happens before typechecking", so this would only work, when the function has a declared type. That's in line with the linked existing improvement in TS 3.7, and to be expected.

🔍 Search Terms

Getter Get accessor must return a value never returning function error throw

✅ Viability 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, new syntax sugar for JS, 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 tracciando il controllo del valore restituito dai getter e la gestione del flusso di controllo delle funzioni dichiarate per non restituire mai, usando la nota di rilascio di TypeScript 3.7 come contesto. Aggiungi una copertura di regressione per un getter che chiama una funzione dichiarata per restituire never e verifica che la diagnostica del getter venga soppressa, mentre i normali percorsi senza restituzione continuino a richiedere un valore.

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

Valutazione

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.