-
Notifications
You must be signed in to change notification settings - Fork 13.2k
Description
Using the latest release-2.1 branch, I'm seeing the following behavior.
I'm writing some React/JSX code, and using a pattern often seen in code in the wild, namely:
var fails = ({myId, ...others}) => <div id={myId}>{others.anything}</div>;However, the above is in error, as the type inferred for ...others is the empty object ({}). Thus the expression within the DIV tags gives the error Property 'anything' does not exist on type '{}'.
If I explicitly type the parameter then all is OK. Namely:
interface Sample {
myId: string;
anything: number;
}
var works = ({myId, ...others}: Sample) => <div id={myId}>{others.anything}</div>;It seems to me that for the ease of writing (and porting existing code), ...others above should default to any, as other untyped parameters do.
This may have already been discussed in some of the other rest/spread discussions. I did trying to find a definitive explanation, but those threads were quite verbose. Apologies if already covered.
Ping @sandersn , @RyanCavanaugh , @mhegazy