Closed
Description
Bug Report
I get a compile error when calling a property method that returns never
using --strict
, when I expect to get no compile error. I am unable to reproduce the error with toplevel functions.
🔎 Search Terms
- never strict label:bug
- never property
- false positive never label:bug
🕗 Version & Regression Information
- I am able to reproduce this behavior with versions 4.1.3 (my application), 4.4.3 (the minimized reproduction above) and 4.5.0-beta (playground link)
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about
never
⏯ Playground Link
💻 Code
Minimized reproduction
❯ cat boom.ts
function boom(): never {
throw new Error('boom')
}
const Outer = {
boom(): never {
throw new Error('boom')
}
}
class Bar {
public boomFunction(): number {
boom()
}
public boomProperty(): number {
Outer.boom()
}
}
🙁 Actual behavior
❯ npx -p [email protected] tsc --strict boom.ts
boom.ts:18:28 - error TS2366: Function lacks ending return statement and return type does not include 'undefined'.
18 public boomProperty(): number {
~~~~~~
Found 1 error.
🙂 Expected behavior
I expected there to be 0 errors because there is no error for boomFunction()
, only boomProperty()
.
Workarounds
- add
return Outer.boom()
. - remove the
--strict
flag.
Metadata
Metadata
Assignees
Labels
No labels