Configure:
Se você estiver usando o código VS (ou se vir um tsconfig.jsonarquivo):
Você deve adicionar a libpropriedade ao seu tsconfig.jsone, em seguida, seu editor usará as definições de tipo de texto datilografado em pacote e também fornecerá inteligência.
Basta adicionar o "lib": ["esnext", "dom"]ao seu tsconfig.jsone reiniciar o VS Code
{
"compilerOptions": {
// ...
"target": "es5",
"lib": ["esnext", "dom"]
// ...
}
}
Veja todas as tsconfig.jsonopções aqui .
Se você estiver usando o Visual Studio ou MSBuild, inclua esta tag:
<TypeScriptLib>esnext, dom</TypeScriptLib>
Veja todas as opções e uso do compilador datilografado do MSBuild aqui .
Verifique seu trabalho:
Se você configurou seu projeto para usar os tipos internos e reiniciou o editor, o tipo resultante será semelhante a esse em vez do tipo anyquando você usar Object.assign:

Nota sobre polyfills e compatibilidade com navegadores mais antigos:
Observe que se você estiver transpilando para o ES5 ou inferior e estiver direcionando o IE11, precisará incluir polyfills, porque o compilador de texto datilografado não incluirá os polyfills para você.
Se você deseja incluir os polyfills (o que você deve), recomendo o uso dos polyfills do core-js.
npm install --save core-js
ou
yarn add core-js
Em seguida, no ponto de entrada do seu aplicativo (por exemplo /src/index.ts), adicione a importação core-jsna parte superior do arquivo:
import 'core-js';
Se você não estiver usando um gerenciador de pacotes, basta colar o seguinte polyfill retirado do MDN em algum lugar do seu código que é executado antes do uso do Object.assign.
if (typeof Object.assign != 'function') {
// Must be writable: true, enumerable: false, configurable: true
Object.defineProperty(Object, "assign", {
value: function assign(target, varArgs) { // .length of function is 2
'use strict';
if (target == null) { // TypeError if undefined or null
throw new TypeError('Cannot convert undefined or null to object');
}
var to = Object(target);
for (var index = 1; index < arguments.length; index++) {
var nextSource = arguments[index];
if (nextSource != null) { // Skip over if undefined or null
for (var nextKey in nextSource) {
// Avoid bugs when hasOwnProperty is shadowed
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
to[nextKey] = nextSource[nextKey];
}
}
}
}
return to;
},
writable: true,
configurable: true
});
}