Created
June 21, 2024 13:34
-
-
Save etherealHero/b0fd9fca6028ae82247aa47cdb72a6ee to your computer and use it in GitHub Desktop.
Revisions
-
etherealHero created this gist
Jun 21, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ /** * @typedef {Object} MyObject * @property {string} knownProperty - Известное свойство */ /** * @returns {MyObject & { [key: string]: any }} */ function createObject() { const obj = { knownProperty: "initial value" }; return obj; } const objFromFunction = createObject(); objFromFunction.newKey = "value"; // Нет ошибки, добавляется новое свойство console.log(objFromFunction.knownProperty); // Подсказка для известного свойства работает console.log(objFromFunction.newKey); // Динамическое свойство тоже доступно