Skip to content

Typescript still checks return type in a lamba that calls a function returning 'never'Β #63714

Description

@kwasimensah

πŸ”Ž 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

Metadata

Metadata

Labels

Design LimitationConstraints of the existing architecture prevent this from being fixed

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions