Within my code, I have implemented the following custom hook:
const count = useDocsCount({
collectionRef: 'notifications',
filter: {
filterKey: 'seen',
operator: '==',
filterValue: false
}
})
This filter object comprises of 3 fields. To ensure accuracy, I validate that the filterKey matches a field from the INotification
interface, which is outlined below:
export interface INotification {
dateCreated: Timestamp,
seen: boolean,
notificationID: string,
text: string,
title: string,
type: TNotificationType
}
My goal is to prompt TypeScript to display an error if the filterKey does not align with any fields in this interface.
It's crucial that this validation occurs in a separate location from the hook itself, as other components rely on this hook and the interface it's based on may change in those components.
Additionally, as a bonus feature, I aim to ensure that if the filterKey is set as 'seen', the filterValue must be of the same type as the 'seen' field in INotification
(boolean).