Secondo MDN, Object.assign() non è ancora supportato da IE e Android. Se si installa una versione tipografico di 2,1 o superiore, però, è possibile utilizzare Object Spread invece:
let obj = { x: 1, y: "string" };
var newObj = {...obj, z: 3, y: 4}; // { x: number, y: number, z: number }
Se non si desidera utilizzare tipografico, quindi ecco una simple polyfill dalla conversione di tipografico del sopra in JavaScript :
Object.assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
var obj = { x: 1, y: "string" };
var newObj = Object.assign({}, obj, { z: 3, y: 4 });
View on Typescript Playground
fonte
2017-03-10 14:33:52
Attenzione con IE. Secondo MDN non è supportato. – lukeatdesignworks
Il browser Android non supporta questo: http://kangax.github.io/compat-table/es6/#test-Object_static_methods_Object.assign – Chris
Se si utilizza la CLI Angolare, trovare 'poyfills.ts' e decommenta il codice che supporta IE9-11. – shammelburg