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
Playground link https://www.typescriptlang.org/play?ts=4.5.0-beta#code/EQVwzgpgBGAuBOBLAxrYBuAUAMxAO1UQHs8oAjIogWwAoBKALijwgDcJ4oBvTKKWABbwiAd2YQxAUXjD4NAOQVq8upgC+mTMhJwoAeRCwOUALzdefcpVqNx7Tj0tP+Q0eKkyicxdZUW+GhpaADYAhmBgUABCoQ7+UAAOIGTBKFbUAGL4hCT0THggVGTGjs58SjbxGk5JKWkVAArCCRywAJ55zIXFcWV8BkbwAHQV9FXqmEA
💻 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 typescript@4.4.3 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.
Bug Report
I get a compile error when calling a property method that returns
neverusing--strict, when I expect to get no compile error. I am unable to reproduce the error with toplevel functions.🔎 Search Terms
🕗 Version & Regression Information
never⏯ Playground Link
Playground link https://www.typescriptlang.org/play?ts=4.5.0-beta#code/EQVwzgpgBGAuBOBLAxrYBuAUAMxAO1UQHs8oAjIogWwAoBKALijwgDcJ4oBvTKKWABbwiAd2YQxAUXjD4NAOQVq8upgC+mTMhJwoAeRCwOUALzdefcpVqNx7Tj0tP+Q0eKkyicxdZUW+GhpaADYAhmBgUABCoQ7+UAAOIGTBKFbUAGL4hCT0THggVGTGjs58SjbxGk5JKWkVAArCCRywAJ55zIXFcWV8BkbwAHQV9FXqmEA
💻 Code
Minimized reproduction
🙁 Actual behavior
🙂 Expected behavior
I expected there to be 0 errors because there is no error for
boomFunction(), onlyboomProperty().Workarounds
return Outer.boom().--strictflag.