-
Notifications
You must be signed in to change notification settings - Fork 64
Description
Currently some function definitions like propEq use the index signature to type object arguments. This seems of limited use, because the supplied object needs to have this index signature explicitly defined. For example.
One of the type signatures of propEq is
propEq<T>(name: string, val: T, obj: {[index:string]: T}): boolean;Using this function with var obj = {a: 1, b: 2} like
propEq('a', 1, obj); // Type erroris correct, however TypeScript complains with:
argument of type 'string' is not assignable to parameter of type 'number' pointing to the a parameter.
This is because obj does not have a index signature. If we add this signature to obj explicitly the type error disappears:
var obj: {[index: string]: number} = {a: 1, b: 2}
propEq('a', 1, obj); // OKThis reason for this behavior is explained in http://stackoverflow.com/questions/22077023/why-cant-i-indirectly-return-an-object-literal-to-satisfy-an-index-signature-re#22077024
I think the requirement that only objects with an index signature can be used is too strict and that we therefore should limit the use of index signature to those cases where it is obviously (but I can not think of one at the moment).
Any thoughts on this issue?