What is the equivalent of `never` TypeScript type in Flow?

198 Views Asked by At

What is the equivalent of never TypeScript type in Flow?

I am working on a project which uses flow for type checking. There I have to define a throwing function. In Typescript we can use never type for function which do not return. I want to do the same with flow but didn’t found anything in the documentation.

I have a condition for invalid types.

if(type == 'a' || type == 'b'){
  throw new Error();
}
return type;

the function which contains this code has a type which does not include "a" and "b". The above code works. But when i move the if condition in a function it does not work.

function throwIfInvalidType(type) {
  if(type == 'a' || type == 'b'){
     throw new Error();
  }
}

And then use the function as below it does not work.

throwIfInvalidType(type)
return type;

https://flow.org/try/#0FAFwngDgpgBAbgQwDYEsAmAVSsC8MDkAxvqNjCgHaKqbYDOMe+C+MAPgQEYmnQzJJwfPNXRY+HSqNrQ6wAGYBXCoRAoA9hRggAFgCd1AdxTyAkhQBqydAAohUAJQBvYDHLy7ZHExbsO9xiZuZ1c3bX0jGAooQxgAUT0DPRsHUIBfYAyFZVUNLQBzKBArJEUoOhSALnhrGVgXNyQimABbMHFcAhYAblDdA2MzS1qbNo7Utz0ixT0tMexerKUVNU0YQuLkMroARiqamg6YBpgmkFb27GqBAJ98XrcTUcvhby7WNg5516D8ELDwgMojF4ol1MkJjAMpNprMLh1FkA

0

There are 0 best solutions below