node.js - Cómo solucionar: Tipo 'Window' no se puede asignar al tipo 'typeof globalThis'
Estoy probando un proyecto de Angular de GitHub. Estoy usando la versión 12 de Node, Angular CLI 9, y he actualizado el package.json.
https://github.com/chat21/chat21-web-widget De estos dos archivos, estoy obteniendo un error durante la compilación. https://github.com/chat21/chat21-web-widget/blob/master/src/app/providers/translator.service.ts https://github.com/chat21/chat21-web-widget/blob/master/src/app/utils/globals.ts Línea 31
let windowContext = window;
if (window.frameElement && window.frameElement.getAttribute('tiledesk_context') === 'parent') {
windowContext = window.parent;
}
Tipo de error: 'Window' no es asignable al tipo 'typeof globalThis'.
windowContext=window.parent;
Creo que este es un problema relacionado con TypeScript, pero no estoy familiarizado con eso.
Respuesta #1
Sí, este error es esperado. Cuando creaste la variable windowContext, no declaraste un tipo, por lo que TypeScript dedujo que windowContext es del tipo "Window & typeof globalThis".
Luego intentaste reasignar la variable, pero la reasignaste con un tipo diferente. window.parent es de tipo "Window". Así que los tipos no coinciden.
puedes intentar esto
let windowContext: any = window;
if (window.frameElement &&
window.frameElement.getAttribute('tiledesk_context') === 'parent') {
windowContext = window.parent;
}
