You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is the behavior in every version I tried, and I reviewed the FAQ for entries about version 3.3 till nightly version 5.5.0-dev.20240404. The version I am using is 5.4.3.
I created a separate function to handle errors, which also involves throwing them. I expected that explicitly stating the return type as never would lead Typescript to infer this and accordingly narrow the types on the variable. However, contrary to my expectations, I received a type error, which seemed to disregard the type guard.
🙂 Expected behavior
I expect that type narrowing behaves identically for arrow functions and traditional functions.
Additional information about the issue
I'm not entirely sure if this is a bug or merely expected behaviour. However, I am confident that type narrowing for arrow and traditional functions should behave similarly. If I'm mistaken, please let me know.
I attempted to replicate this in the playground, but it seems not all configuration settings are available there, so I am including my TypeScript configuration. Additionally, here is some extra environment information.
🔎 Search Terms
"Inconsistent", "Arrow", "Narrowing", "Type Guard"
🕗 Version & Regression Information
⏯ Playground Link
https://www.typescriptlang.org/play?noImplicitAny=false&strictNullChecks=false&strictFunctionTypes=false&strictPropertyInitialization=false&strictBindCallApply=false&noImplicitThis=false&noImplicitReturns=false&alwaysStrict=false&experimentalDecorators=true&target=7&jsx=0&module=1&allowSyntheticDefaultImports=true&ts=5.4.3#code/MYewdgzgLgBFAWAnEB3Ago5KYF4YAoBKALhjAFMA3cxXAPhgG8BYAKBjiVTPOwFFMIRPgBEAZRABbcjAHJEIwgG42AXzZsAZgFcwwKAEtwnLADFd+o2AIke1Wi3YnuFfoOEiA8ghqz3ilVZ1VjZgABsAQwgIGFMQECY2DgAHRANKCKgZACMI4QAPUmg0sABzGAAfMm0wsNtigzLEpw4DTQJ83Bw8MBq65o5B53RBFCJAoeCkwcRyKG1Ea3ylGAB6VZgAFXgDGKgAT2SZGnkIADpp4KnWcKiYgCE8gZhU9MyZTXj8faKoEvKqr1avU-o1yo4hm0CPsuj0+oRnkMEGYLIZwONphxrkNZvNFjB9it1lsdjEUEIANbnS5qIA
💻 Code
🙁 Actual behavior
I created a separate function to handle errors, which also involves throwing them. I expected that explicitly stating the return type as
never
would lead Typescript to infer this and accordingly narrow the types on the variable. However, contrary to my expectations, I received a type error, which seemed to disregard the type guard.🙂 Expected behavior
I expect that type narrowing behaves identically for arrow functions and traditional functions.
Additional information about the issue
I'm not entirely sure if this is a bug or merely expected behaviour. However, I am confident that type narrowing for arrow and traditional functions should behave similarly. If I'm mistaken, please let me know.
I attempted to replicate this in the playground, but it seems not all configuration settings are available there, so I am including my TypeScript configuration. Additionally, here is some extra environment information.
VSCODE:
Package.json
Ts Config:
The text was updated successfully, but these errors were encountered: