-
Notifications
You must be signed in to change notification settings - Fork 99
[@types/ember bug] - Ember.set doesn't work w/ ES6 classes #286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This has something to do with the new @dfreeman @dwickern @jamescdavis If you could poke at this sometime soon, I would love to find a near-term solution that doesn't involve weakening the types -- I just have run out of time trying to figure it out. Until we can arrive at some root cause and fix it, I'll add the failing test case above and relax the types around It's clear, one factor that contributed to this problem making it into a release is very thin test coverage in some areas. Part of my debugging process involved creating dozens of new tests -- particularly around some of the tricker areas of the types (computed properties, |
The PR related to this issue was just merged. This means we no longer have type safety when using |
I spent a little time on this this evening and I think either I have a fundamental misunderstanding of some aspect of the type system or there's a bug in the compiler around declare const brand: unique symbol;
type Wrapped<T> = { [brand]: T };
type Unwrap<T> = T extends Wrapped<infer U> ? U : T;
declare function set<T, K extends keyof T>(obj: T, key: K, value: Unwrap<T[K]>);
class Foo {
prop: Wrapped<string>;
method() {
// Argument of type '"hi"' is not assignable to parameter
// of type 'Unwrap<this["prop"]>'.
set(this, 'prop', 'hi');
}
}
// Works as expected
set(new Foo(), 'prop', 'hi'); |
If I understand the situation correctly, it's not only:
Rather, we no longer have type safety when using class Example extends Controller {
title = "hello";
anAction() {
this.set('title', 42); // <- should be a type error: found number, expected string
}
} Removing this line fixes my example, but I don't know what else it would break. |
@ef4 which version of the types, and which version of typescript are you using? |
|
As far as I can tell, this remains an issue on the TS side, but is largely irrelevant since every use of |
Which package(s) does this problem pertain to?
What are instructions we can follow to reproduce the issue?
Failing test case
Now about that bug. What did you expect to see?
I expected to be able to set properties on my ember objects with no type errors
The text was updated successfully, but these errors were encountered: