The error message you're encountering is because artikulNameMap is not defined within the scope of the component's render method. Instead, the getArtikulNameMap function, which generates this map, is defined. Here's how you can fix the error:
The problem occurs when trying to access artikulNameMap[selectedItem] within the JSX. To avoid this issue, you should first call getArtikulNameMap to get the map, and then use it to access the required data.
Here's the corrected part of the code in the JSX:
jsx
{selectedItem ? (
<div>
<h3>Детали для {getArtikulNameMap()[selectedItem]}</h3>
<p>
Общая сумма "К перечислению":{' '}
{calculateTotal('К перечислению Продавцу за реализованный Товар')} руб.
</p>
<p>Продано: {calculateTotal('Кол-во')} шт.</p>
</div>
) : (
<div>
<h3>Все</h3>
<p>
Общая сумма "К перечислению":{' '}
{calculateTotal('К перечислению Продавцу за реализованный Товар')} руб.
</p>
<p>Продано: {calculateTotal('Кол-во')} шт.</p>
</div>
)}
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
<input
type="file"
accept=".xlsx, .xls"
id="fileInput"
className={styles.hiddenInput}
onChange={handleInputChange}
/>
<p>Перетащите файл сюда или нажмите для выбора файла</p>
<button
className={styles.uploadButton}
onClick={() => document.getElementById('fileInput')?.click()}
>
Выбрать файл
</button>
{selectedItem ? (
<div>
<h3>Детали для {artikulNameMap[selectedItem]}</h3>
<p>
Общая сумма "К перечислению":{' '}
{calculateTotal('К перечислению Продавцу за реализованный Товар')} руб.
</p>
<p>Продано: {calculateTotal('Кол-во')} шт.</p>
</div>
) : (
<div>
<h3>Все</h3>
<p>
Общая сумма "К перечислению":{' '}
{calculateTotal('К перечислению Продавцу за реализованный Товар')} руб.
</p>
<p>Продано: {calculateTotal('Кол-во')} шт.</p>
</div>
)}
<div>
<h3>Общая сумма дополнительных услуг</h3>
<ul>
{additionalColumns.map((colName) => (
<li key={colName}>
{colName}: {calculateTotal(colName)} руб.
</li>
))}
</ul>
</div>
<div>
<h3>К выплате</h3>
<p>{calculatePayout()} руб.</p>
</div>
</div>
);
};
export default ExcelUploader; Cannot find name 'artikulNameMap'. Did you mean 'getArtikulNameMap'?ts(2552)
index.tsx(61, 9): 'getArtikulNameMap' is declared here.
⚠ Error(TS2552)
By calling getArtikulNameMap() directly, you obtain the artikulNameMap and avoid the scope issue. This change should resolve the TypeScript error you encountered.