I have the following typescript code which doesn't seem to be producing any TS validation errors. But I'm not sure why it is working. So, the T that is defined on this line
const openModal = <T>({ data = null, modalId }: TOpenModal<T>) => ({
represents the type definition of the object which contains all the props. In TOpenModal I am using T to type data, but if T represents the whole object (not just data) why does it work?
type TOpenModal<T> = {
data: T | null
modalId: string
}
const openModal = <T>({ data = null, modalId }: TOpenModal<T>) => ({
type: OPEN_MODAL,
payload: {
data,
modalId,
},
});