-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Consider only showing builders in object literal completions its contextual type has an index signature #4089
Comments
Seems like a good idea |
Though I recall another edge condition is that we would need to allow a builder for the empty type as well. |
I believe you would also want a builder when the contextual type is from a type assertion, because you are allowed to specify extra properties there as well. You may want to look at isKnownProperty in the checker for inspiration. |
@JsonFreeman sorry that's what I originally meant, I wrote "completion" instead of "a builder" in the original issue. Corrected. |
Yes, but I meant that maybe the builder would always be shown in a type assertion, since type assertions do not view their expressions as fresh. |
Right, that was what I was getting at. And actually there's another problem - consider the following: function f(options: FooOptions): void;
function f(options: BarOptions): void;
function f(options: any) { } Provided that This would be bad experience. We should either supply properties from both |
I think that is a different issue. You'd need to detect whether multiple overloads are involved in obtaining the contextual type, and decide on a policy for this case. I think it may be acceptable to pick one and show a builder. Alternatively, you could try to collect them from all the overloads, but I think that would be complicated, and not that useful. I would also try to have completion and signature help agree on which overload the user is likely trying to call. |
We'd rather error on the side of not restricting the typing here. |
Since users are no longer allowed to have excess properties in an object literal, it might be appropriate to only show a builder when the contextual type of an object literal has no index signature.
For instance:
However, this may not be sufficient; in the presence of a type assertion, one actually does want to allow a builder, since this is one of the recommended workarounds anyway:
The text was updated successfully, but these errors were encountered: