-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Adding indexer to global Object makes other interfaces incompatible with Object #835
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
I think this is just a bug and we aren't considering the indexer extensions to Object when checking the apparent type of |
This is seems to be according to the spec -- the augmented apparent type of |
Confirmed by design. The ideal fix would be to replace We can talk about other fixes if you have more detailed use cases. Were you using the indexer to avoid |
I suspect this is one of the reasons that it was used; I am still looking through to figure out and will update with more information as I have it. |
@RyanCavanaugh Here’s one pattern that adding the indexer to Object was “fixing”: interface Foo {
// ...
}
function mixin(target:Foo, source:Foo):Foo {
for (var key in source) {
if (key === 'somethingNotToCopy') {
continue;
}
// error TS7017: Index signature of object type implicitly has an 'any' type.
target[key] = source[key];
}
return target;
} 1.0 would give TS7017 also until putting the indexer on Object; in 1.1 it doesn’t matter, it will complain anyway. Using explicit |
Here are some other patterns triggering the new(ish) Feature detect something that isn’t in lib.d.ts: has.add('dom-pointerevents', Boolean(window['PointerEvent'])); This one could use Late binding methods: function lateBind(target:Object, method:string):(...args:any[]) => any {
return function ():any {
return target[method].apply(target, arguments);
};
} This one would need to define target as I think my remaining examples are all pretty much the same; |
Between 0.9.1 and 0.9.5 the explicit indexer was removed from Object. Between 1.0 and 1.1, code that adds the indexer back to Object causes type comparison failures:
Putting an indexer on Foo makes it work.
This is probably an OK error since adding back the indexer like this to Object should probably be considered an anti-pattern, and since in ES5 you can create inheritance patterns that don’t extend from Object, but it should at least be documented as a known breaking change.
The text was updated successfully, but these errors were encountered: