Relative Content

Tag Archive for javascriptjsdoc

Set the key type in the object based on the contents of the array

const keys = [‘x’, ‘y’, ‘z’]; /** @typedef ??????? KeyType`*/ //is important that the type is based on the values from the keys /** @type {{[key: KeyType]?: number}} */ const obj = {}; for(const k of keys){ obj[k] = Math.random(); // good } obj[‘foo’] = 3; // IDE should show warning, but it doesn’t care […]