-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Object key signature is not taken into account with destructive assignment on method definition level #15660
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
as a result The second class If class MyClass implements IMyInterface {
onChange({config = undefined}) {
console.log(config);
}
} or give it an explicit type: class MyClass implements IMyInterface {
onChange({config} : any) {
console.log(config);
}
} you can always give type, and you would see a similar error. class MyAnotherClass implements IMyInterface {
onChange(changes: { config: number }) {
const { config } = changes;
console.log(config);
}
} |
But this doesn't violate typings, and TS says it does:
doesn't |
but it can not be there at all. |
but again, does it violate typing? |
cause |
ohh, I though in this case changes aren't should this be matched this way? we are implementing specific method, so it's arguments should be matched with types provided in interface - this sounds logical for me |
|
so, if type is not specified the method's it is considered to be |
correct. you can find more details about this in #10570 |
Looks like we have some issues here that need to be addressed after all... interface IMyInterface {
onChange(changes : {[key : string] : {newValue : any, oldValue : any}})
}
class MyClass implements IMyInterface { // Error
onChange({ config }) {
}
}
class MyClass2 implements IMyInterface { // OK
onChange({ config }: { config: any }) {
}
} |
Uuufff! Glad that it helped to undercover some real issues at the end. Thanks for detailed explanation. And once again: |
@mhegazy, I think this captures the bug you found without any destructuring. Did I understand it correctly? interface IMyInterface {
onChange(changes : {[key : string] : {newValue : any, oldValue : any}})
}
class MyClass2 implements IMyInterface { // OK, but should be error
onChange(x: { config: any }) {
}
} |
well there are a few issues here we need to understand and find a consistent place for.. these should all behave the same: interface IMyInterface {
onChange(changes : {[key : string] : {newValue : any, oldValue : any}})
}
class MyClass1 implements IMyInterface { // OK, but should be error
onChange(x: { config: any }) {
}
}
class MyClass2 implements IMyInterface { // OK, but should be error
onChange({ config }) {
}
}
class MyClass3 implements IMyInterface { // OK, but should be error
onChange({ config }: { config: any }) {
}
} arguable, remove the error to match things like: var index: { [key: string]: { newValue: any, oldValue: any } };
var { config } = index;
var tmp = index;
var config = tmp.config; |
Since this is comparing assignability of parameters, there is bivariance. So it shouldn't be an error. |
Uh oh!
There was an error while loading. Please reload this page.
TypeScript Version: 2.3.2
Code
Expected behavior:
compiled without errors
Actual behavior:
Note: this affects Angular >1.5 users when writing component controllers and implementing
$onChanges
methodThe text was updated successfully, but these errors were encountered: