Closed as not planned
Description
Which package(s) does this problem pertain to?
- [ x ] @types/ember__object
What are instructions we can follow to reproduce the issue?
ember new sample; cd ./sample # Create a new ember app
ember install ember-decorators # Set up decorator support
ember install ember-cli-typescript # Set up typescript support
Reproduction Case
import EmberObject, {set} from "@ember/object";
class Sample extends EmberObject {
name!: string;
}
const sample: Sample = Sample.create({ name: "test" });
sample.set("name", 12346); // No error => Incorrect
sample.set<Sample>("name", 12456); // Error => Correct
set(sample, "name", 12346); // Error => Correct
Now about that bug. What did you expect to see?
In all cases typescript should throw an error.
What happened instead?
sample.set("name", 12346);
is accepted by the typescript compiler.
Note
Observable
in package @ember/object/observable
contains an overloaded function set
with the following definitions:
set<K extends keyof this>(key: K, value: this[K]): this[K];
set<T>(key: keyof this, value: T): T;
The second function seems to be unnecessary.
Workaround and possible solution
Remove set<T>(key: keyof this, value: T): T;
from Observable
.
Metadata
Metadata
Assignees
Labels
No labels