ember-cli-typescript
ember-cli-typescript copied to clipboard
Type error with .set() since TypeScript 3.6
Which package(s) does this problem pertain to?
@types/ember__object
Repro steps
The following code reports no typing errors in TypeScript 3.5.x, but gives errors as of TypeScript 3.6 that are still present in TypeScript 3.7.2.
import EmberObject, { set } from "@ember/object"
class Foo extends EmberObject {
public version!: number
}
class Bar extends EmberObject {
public version!: number
public name!: string // Note: removing this line makes the error below go away
}
function test(a: Foo | Bar) {
// Global set type checks correctly, no problems here
set(a, "version", 1)
// But using .set() gives `error TS2349: This expression is not callable.`
a.set("version", 1)
}
Expected result would be for the above code to continue to be error-free when upgrading TypeScript. Something to do with the union type appears to be the issue.
Workaround is to use global set().
Thanks.
Thanks for reporting! Looks like our chicanery to get EmberObject#set through the type system has taken another hit. :sad: One of us will try to get this fixed sometime soon!
As far as I can tell, this may remain an issue on the TS side, but is largely irrelevant since every use of this.get() and this.set() in Ember can be safely replaced with a normal ES property access or assignment statement, including in Ember Data. Closing as “not planned” accordingly.