microsoft / microsoft/TypeScript

Never returning functions should disable getter return requirement

Abierto
#52,214 1 comentario 3 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Awaiting More Feedback Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
1 d 19 h
PR fusionados (30 d)
117

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza rastreando la comprobación del valor de retorno de los getters y el manejo del flujo de control de las funciones declaradas para no retornar nunca, usando la nota de lanzamiento de TypeScript 3.7 como contexto. Añade cobertura de regresión para un getter que llama a una función declarada para retornar never y verifica que el diagnóstico del getter se suprima, mientras que las rutas ordinarias que no retornan siguen requiriendo un valor.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
typescript
Área
compilers
Tipo de issue
Nueva funcionalidad
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.