facebook / facebook/flow

The `throw` operator should be more strict

Abierto
#2,172 3 comentarios 0 reacciones 0 asignados Ver en GitHub
linter
Lenguaje dominante
Rust
Estrellas
22.3k
Forks
1.9k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

I tried searching, but I didn't find any existing issues about this.

Currently, using version 0.30.0 of flow-bin, the following code shows no errors:

```
function foo() {
throw null;
}

function bar() {
throw 5;
}

function qux() {
throw [];
}
```

It seems that the `throw` operator will accept any type.

I think it should only accept `Error`. If that is too restrictive, it could be relaxed to `Error | string`.

This actually bit me when I was writing a function which accepts an optional argument: if the argument is not provided, then it will `throw` `undefined`, which is not what I wanted.

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.