microsoft / microsoft/TypeScript
refactoring for extracting return type of a function
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
Search terms
refactoring extract return type function method interface inferred
Suggestion
A new refactoring for function expressions that extracts the return type of the function as an interface or type.
Use Cases
Imagine a complex function that combines many types of data into a complex object. Compiler can infer the return type, but writing it out by hand takes time. Type needs a name when you want to use it elsewhere in the code (for example as a parameter type for another function).
Examples
Imagine A, B, C, D are non trivial types. (e.g. objects with many properties)
before:
function fooFunc(a: A, b: B, c: C, d: D) {
return {
...a,
...b,
foo: {...c, d}
}
}
after:
type FooFuncReturn = A & B & { foo: C & D }
// or when possible an interface type with would be even better
function fooFunc(a: A, b: B, c: C, d: D): FooFuncReturn {
return {
...a,
...b,
foo: {...c, d}
}
}
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.
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
El issue no nombra archivos, pruebas ni puntos de entrada. Empieza por localizar la infraestructura de refactorización existente de TypeScript y, después, define cómo debe gestionar la extracción solicitada del tipo de retorno las formas de tipo e interfaz del ejemplo; se considera terminado cuando la refactorización funciona para el caso de uso de expresión de función indicado y su salida está cubierta por pruebas.
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
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100