Created
June 21, 2024 13:34
-
-
Save etherealHero/b0fd9fca6028ae82247aa47cdb72a6ee to your computer and use it in GitHub Desktop.
This file contains 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 characters
/** | |
* @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); // Динамическое свойство тоже доступно |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment