Skip to content

Instantly share code, notes, and snippets.

@etherealHero
Created June 21, 2024 13:34
Show Gist options
  • Save etherealHero/b0fd9fca6028ae82247aa47cdb72a6ee to your computer and use it in GitHub Desktop.
Save etherealHero/b0fd9fca6028ae82247aa47cdb72a6ee to your computer and use it in GitHub Desktop.
/**
* @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