question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Type errors on computed properties when upgrading to TypeScript 3.7

See original GitHub issue

Which 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:open
  • Created 4 years ago
  • Reactions:3
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
chriskrychocommented, Jan 8, 2021

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).

2reactions
Alonskicommented, Dec 16, 2019

I am also seeing a similar issue. Here is the code for reference:

const thisIsABool = this.someModel.isNew;
if (thisIsABool) {
  return false;
} 

image

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found