TypeScript 2.1 now supports object spread/rest, so no workarounds are needed anymore!
TypeScript s
I've accepted Nitzen Tomer's answer because it was the basic idea I was going for.
As a more generalized solution this is what I ended up going with:
export function rest(object: any, remove: {[key: string]: any}) {
let rest = Object.assign({}, object);
Object.keys(remove).forEach(key => delete rest[key]);
return rest;
}
So I can use it like this:
const {a, b, c} = props;
const htmlProps = rest(props, {a, b, c});
And once TypeScript supports object rest/spread I can just look for all usages of rest()
and simplify it to const {a, b, c, ...htmlProps} = props
.