π Search Terms
lambda never return type match
π Version & Regression Information
- This is the behavior in every version I tried, and I reviewed the FAQ for entries (didn't find a relevent one)
β― Playground Link
https://www.typescriptlang.org/play/?ts=6.0.0-dev.20260416#code/FAYwNghgzlAEBiB7RBJAtgBzLA3sWBsARhAE4AUApqaYqQFywCiNdAlIwHaUBu1u+QkIAuAC1oB3WNVqkA3IIIBfYMBWhEnKMNgBLTNgC8sblKSoD5NguBhKOgGaxjVrgFc0RfoYB8AoQD0AWKSJpRSLLJWcrBBEnQA1nASopScsGK6cGC63HpwnIg6IIhoaGnClAAminoGAHQkFKbMrBRs1mqqwEA
π» Code
class FooImpl {
bar(error: Error): never {
throw error;
}
}
const impl = new FooImpl();
let f = (): number => {
//throw new Error(); //works when this line is not commented
impl.bar(new Error());
}
π Actual behavior
the definition of f has the error
A function whose declared type is neither 'undefined', 'void', nor 'any' must return a value.
π Expected behavior
the definition of f is valid typescript
Additional information about the issue
This works if I throw he exception directly in the function instead of through a member function
π Search Terms
lambda never return type match
π Version & Regression Information
β― Playground Link
https://www.typescriptlang.org/play/?ts=6.0.0-dev.20260416#code/FAYwNghgzlAEBiB7RBJAtgBzLA3sWBsARhAE4AUApqaYqQFywCiNdAlIwHaUBu1u+QkIAuAC1oB3WNVqkA3IIIBfYMBWhEnKMNgBLTNgC8sblKSoD5NguBhKOgGaxjVrgFc0RfoYB8AoQD0AWKSJpRSLLJWcrBBEnQA1nASopScsGK6cGC63HpwnIg6IIhoaGnClAAminoGAHQkFKbMrBRs1mqqwEA
π» Code
π Actual behavior
the definition of f has the error
π Expected behavior
the definition of f is valid typescript
Additional information about the issue
This works if I throw he exception directly in the function instead of through a member function