Dzień dobry,
Uczę się Reacta + TypeScript z samouczka i mam taki oto problem:
const [product, setProduct] = useState("electricity");
const defaultProps = {
price: {
electricity: 0.51,
gas: 4.7,
oranges: 3.79,
},
};
const selectPrice = (select: any) => {
console.log(defaultProps.price[select]);
};
const handleSelect = (e: React.ChangeEvent<HTMLSelectElement>) => {
setProduct(e.target.value);
};
<Cash price={selectPrice(product)} />
<select value={product} onChange={handleSelect}>
<option value="electricity">electricity</option>
<option value="gas">gas</option>
<option value="oranges">oranges</option>
</select>
Problem jest w metodzie `selectPrice()``, bo wyświetla błąd
Element implicitly has an 'any' type because expression of type 'any' can't be used to index type '{ electricity: number; gas: number; oranges: number; }'.ts(7053)
Dodam, że w samouczku w którym jest używany JavaScript działa to bez problemu.