Consider this example:
function foo<T>(t: T): boolean {
return t === 1;
}
I get This condition will always return 'false' since the types 'T' and 'number' have no overlap..
The error goes away if I change it to:
function foo<T extends any>(t: T): boolean {
return t === 1;
}
I thought T could be any by default, so why did I need extends any? Without extends any, what type does TS expect T to be?
Edit, actual function:
function cleanObj<T>(
obj: ObjectOf<T>,
): ObjectOf<T> {
const newObj = {};
for (const k of Object.keys(obj)) {
if (obj[k] !== null && typeof obj[k] !== 'undefined' && obj[k] !== false) {
newObj[k] = obj[k];
}
}
return newObj;
}