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
abstractclassA{statica: ()=>void;publicstaticb(): void{if(this.a){console.log('called function b and function a is defined');}else{console.log('called function b and function a is not defined')}}}classXextendsA{}classYextendsA{statica(){//}}X.b();Y.b();
🙁 Actual behavior
The error "This condition will always return true since the function is always defined. Did you mean to call it instead?ts(2774)" is displayed on this.a in function b of class A.
🙂 Expected behavior
A static function in an abstract class does not need to be defined. The error should therefore not be displayed.
The text was updated successfully, but these errors were encountered:
oakgary
changed the title
compiler assumes a static function in an abstract class needs to be defined
ts assumes a static function in an abstract class needs to be defined
May 7, 2021
Duplicate #27899; static members are assumed to have actually been initialized and what you're seeing here is a "missing" error. You should mark this property as optional if it's intentionally sometimes-not-present
Duplicate #27899; static members are assumed to have actually been initialized and what you're seeing here is a "missing" error. You should mark this property as optional if it's intentionally sometimes-not-present
Actually it is unintentional sometimes-not-present as you cannot make static methods abstract.
The check in function b is there to make sure it is defined.
For anyone stumbling upon this in the future. The error is resolved by marking the function as optional, as suggested by RyanCavanaugh:
abstractclassA{statica?: ()=>void;publicstaticb(): void{if(this.a){console.log('called function b and function a is defined');}else{console.log('called function b and function a is not defined')}}}classXextendsA{}classYextendsA{statica(){//}}X.b();Y.b();
Bug Report
🔎 Search Terms
This condition will always return true since the function is always defined. Did you mean to call it instead?ts(2774)
static method in abstract class
🕗 Version & Regression Information
This changed between versions 3.8.3 and 4.2.4.
The bug is not fixed in the nightly version.
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
The error "This condition will always return true since the function is always defined. Did you mean to call it instead?ts(2774)" is displayed on this.a in function b of class A.
🙂 Expected behavior
A static function in an abstract class does not need to be defined. The error should therefore not be displayed.
The text was updated successfully, but these errors were encountered: