Type errors on computed properties when upgrading to TypeScript 3.7
See original GitHub issueWhich package(s) does this problem pertain to?
@types/ember__object
Repro steps
The 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.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:3
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Documentation - TypeScript 3.7
TypeScript 3.7 Release Notes. ... error: Property 'toUppercase' does not exist on type 'string'. // Did you mean 'toUpperCase'?.
Read more >Announcing TypeScript 3.7 - Microsoft Developer Blogs
We're thrilled to announce the release of TypeScript 3.7, a release ... error: Property 'toUppercase' does not exist on type 'string'.
Read more >How to define a type to computed properties in typescript?
I have this below code and I'm receiving a typescript warning error at [context!.label] which indicates that a computed property name must be...
Read more >TypeScript interface vs. type - pawelgrzybek.com
Unfortunately we cannot take advantage of computed properties in an interface declaration. Compiler error caused by using computed ...
Read more >Overview - TypeScript
In TypeScript 3.7, the compiler itself will take advantage of this feature so ... a string literal, or a computed property name of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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).
I am also seeing a similar issue. Here is the code for reference: