-
Notifications
You must be signed in to change notification settings - Fork 64
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
limited use of [index:string] #10
Comments
I have just trapped on this, and it confused me a lot. I expected "props" to have the same signature as "prop" except for input args. Why isn't it so? I believe loosing a bit of type safety is a affordable trade off here. At least there could be all possible overloads to choose from.
|
Hey, I'm sorry for chiming in, but I think there are a lot of issues here:
1.a) I really don't understand the third to six lines of the type signature in
Shouldn't it be:
Or better yet,
What do you think? |
Hum, I stand corrected, this seems to only be fixed on typescript 1.9, which is now bleeding edge / alpha. So, I guess if we are still some months away of having this PR fixed in a more 'production ready' environment :( |
That explains why my quick try wasn't able to reproduce it. |
At this point, TS 2.0 is stable, so the original issue should no longer be a concern. |
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
isUsing this function with
var obj = {a: 1, b: 2}
likeis correct, however TypeScript complains with:
argument of type 'string' is not assignable to parameter of type 'number'
pointing to thea
parameter.This is because
obj
does not have a index signature. If we add this signature toobj
explicitly the type error disappears:This 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?
The text was updated successfully, but these errors were encountered: