I can't get this to work, not sure how to explain the type to typescript for the following code:
interface hasLength {
length: number;
}
type CompareFn = <T> (a: T, b: T) => boolean
const compare = (compareFn: CompareFn, a: hasLength, b: hasLength) =>
compareFn(a, b)
const compareFn: CompareFn = (a, b) => a.length === b.length//error here
const otherCompare: CompareFn = (a, b) => a === b
console.log(compare(compareFn, [1], [2]))
console.log(compare(compareFn, 'a', 'b'))
console.log(compare(otherCompare, [1], [2]))
The compare function gets 2 parameters of the same type or interface and is used in the function compare. The error is Property 'length' does not exist on type 'T'.