I need to extend the interface element of the house. Implemented in this way. Here everything works without errors.
interface MyTileElement extends HTMLElement { tile: Tile; } interface Document { createElement(tagName: "space-tile"): MyTileElement; } class Tile { element: MyTileElement; constructor(){ this.element = document.createElement("space-tile"); this.element.tile = this; } } let n = 2; But it is worth adding export or import, immediately typescript throws an exception:
interface MyTileElement extends HTMLElement { tile: Tile; } interface Document { createElement(tagName: "space-tile"): MyTileElement; } class Tile { element: MyTileElement; constructor(){ this.element = document.createElement("space-tile"); //Error:(13, 9) TS2322:Type 'HTMLElement' is not assignable to type 'MyTileElement'. // Property 'tile' is missing in type 'HTMLElement'. this.element.tile = this; } } let n = 2; export {n} // Добавленная строчка I would like to know why this happens and how to get out of the difficulty.