How do I generically iterate over the properties of an arbitrary object in TypeScript?
问题 This is a pretty common JavaScript pattern: function mapThruWrapper(module) { const replacement = {} Object.getOwnPropertyNames(module).forEach(function(key) { const val = module[key] if (val instanceof Function) { replacement[key] = wrapperFunc.bind(null, val) } else { replacement[key] = val } }) return replacement } I'm trying to strongly type this in TypeScript, and I've gotten as far as something like the following: function mapThruWrapper<M extends { [X: string]: unknown }>(module: M): M