-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
propEq type definition does not guarantees type safety #476
Comments
Thank you @peterreisz for pointing this out. I copied the definitions from |
Released with |
@selfrefactor there is a problem with the interface MyType {
optional?: string | number;
}
function propEqWithRecord<K extends string | number, V>
(propToFind: K, valueToMatch: V, obj: Record<K, V>): boolean {
return false;
}
function propEqWithoutRecord<K extends keyof T, T>
(propToFind: K, valueToMatch: T[K], obj: T): boolean {
return false;
}
const myObject: MyType = {};
const valueToFind = '1111';
const optionalValueToFind: string | number | undefined = '1111';
// These will not compile
propEqWithRecord('optional', valueToFind, myObject);
propEqWithRecord('optional', optionalValueToFind, myObject);
// These will compile
propEqWithoutRecord('optional', valueToFind, myObject);
propEqWithoutRecord('optional', optionalValueToFind, myObject); |
@peterreisz I will run |
Released with |
The current definition accepts any as the last parameter
The type safe solution would be something like this:
The text was updated successfully, but these errors were encountered: