microsoft / microsoft/TypeScript
Refactorings to convert from function declarations to function expressions
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 1 d 19 h
- PR fusionados (30 d)
- 117
Descripción
Suggestion
🔍 Search Terms
refactoring quick fix vs code action
✅ 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.
⭐ Suggestion
We already have refactorings to convert function expressions (arrow or non-arrow) to a function declaration, e.g. we can use "convert to named function" on both of these:
const fn1 = function () {
return 1;
};
const fn2 = () => {
return 1;
};
However, there is no refactoring to convert in the opposite direction—from a function declaration to a function expression.
I would like to suggest adding these refactorings so we cover all possibilities.
Note we do already have these refactorings (https://github.com/microsoft/TypeScript/pull/28250):
- "Convert to arrow function"
- "Convert to anonymous function"
However these only work on function expressions—they don't work on function declarations. Perhaps we could fix this by extending the scope of those refactorings so they do work on function declarations.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza examinando las refactorizaciones existentes "Convert to arrow function" y "Convert to anonymous function", centrándote en cómo gestionan actualmente las function expressions. Amplía el ámbito de la refactorización correspondiente a las function declarations y verifica que las declarations puedan convertirse a las formas solicitadas sin cambiar el comportamiento en tiempo de ejecución.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- javascript, typescript
- Área
- devtools
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100