I seem to be encountering an error that I can't quite decipher. Even though I've clearly set the type of first
as a number
, the code still doesn't seem to work properly. Can someone provide insights on how to fix this issue?
function divide<T, U>(first: T, second: U): number {
return first / second;
}
const result = divide<number, number>(40, 2);
The TypeScript error message that's causing confusion is as follows:
5:12 The left-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
3 | const TitleBar = () => {
4 | function divide<T, U>(first: T, second: U): number {
> 5 | return first / second;
| ^
6 | }
7 |
8 | const result = divide<number, number>(40, 2);