microsoft / microsoft/TypeScript
noImplicitReturnType [Suggestion]
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
We have noImplicitReturns which is great and helps tick up silly mistakes but it woud great to have noImplicitReturnType as well.
So what would noImplicitReturnType do?
Currently we can write a function like so:
function life () {
return 42;
}
let x = life(); // Number
So all is great, TypeScript works out the return type nicely for us.
function life (x: boolean) {
if (x) {
return 'hi';
} else {
return 42;
}
}
let y = life(true); // Number / String
This is where things start to go a little crazy. TypeScript records y as of type number | string which is of course acurate. But what if i wanted this function to only return strings?
We already have support for that with limited modifications
function life (x: boolean): string {
if (x) {
return 'hi';
} else {
return 42; // Type '42' is not assignable to type 'string'.
}
}
let y = life(true);
And as a result TypeScript nicly throws an error.
So my suggestion is that in much the same way as with noImplicitAny and let enforcing strict typeing an argument is added in the form of noImplicitReturnType which for my first example (only a single return) wouldn't have any effect but for the second would throw an error instead of typing the function as number | string
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 comparando las opciones existentes noImplicitReturns y noImplicitAny con el comportamiento propuesto de noImplicitReturnType descrito en los ejemplos. Determina los diagnósticos previstos para las funciones cuyo tipo de retorno inferido es una unión, y define qué se consideraría completo para la nueva opción del compilador; el issue no menciona archivos ni 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
- 30/100