@types/ember__objectThe following code reports no typing errors in TypeScript 3.6.3, but gives errors in TypeScript 3.7.2.
declare class MyClass {
isNew: Ember.ComputedProperty<boolean>
}
function foo(a: MyClass): boolean {
// TS2322: Type 'ComputedProperty<boolean, boolean>' is not assignable to
// type 'boolean'.
return a.isNew
}
function bar(a: MyClass): void {
// TS2774: This condition will always return true since the function is always
// defined. Did you mean to call it instead?
if (a.isNew) {
// ...
}
}
The two errors above are likely caused by the same underlying issue. The expected result is no errors upgrading from TS 3.6 to 3.7. This issue was noticed due to new type errors when using the DS.Model.isNew property on instances of Ember Data models.
The workaround appears to be to use get() instead of direct property access.
Thanks.
Thank you for reporting this!
This appears (at very first blush and without having investigated at all) to be a case where TS 3.7 is actually being more strictly correct. Types defined as ComputedProperty<T> or a descendant thereof do require the use of get to unwrap them.
However, this likely points to an issue with our Ember Data types, in that most things in Ember Data (everything that isn't an async relationship, basically) should Just Work⢠with normal property access. We appreciate the report and will hopefully get a fix in place soon!
I am also seeing a similar issue. Here is the code for reference:
const thisIsABool = this.someModel.isNew;
if (thisIsABool) {
return false;
}

What was the actual code that caused this? I assume it wasnāt a local declaration of a ComoutedProperty? š
Is there any update on this? The interaction between the ember/no-get lint rule and the need to call get to "unwrap" these computed properties is frustrating.
Hadnāt been any motion, but is likely to be a lot of motion in related spaces starting in about two weeks: weāve kicked off a āstrike teamā with the aim of getting official TS support in Ember and things like this will absolutely get addressed as part of that (though the result will be months of effort to get there).
Most helpful comment
Hadnāt been any motion, but is likely to be a lot of motion in related spaces starting in about two weeks: weāve kicked off a āstrike teamā with the aim of getting official TS support in Ember and things like this will absolutely get addressed as part of that (though the result will be months of effort to get there).