I have been using typescript in my projects for a month and there're some doubts that I'm struggling with.
Is there a pattern/recommended way to organize types in project architecture?
Let's suppose we have a context with the following interfaces:
export type ToastMessageType = 'info' | 'success' | 'error';
export interface ToastMessageData {
id: string;
title: string;
description: string;
type: ToastMessageType;
}
export interface ToastsStateContextData {
messages: ToastMessageData[];
}
export interface ToastsDispatchContextData {
addToast: (message: Omit<ToastMessageData, 'id'>) => void;
removeToast: (id: string) => void;
}
And there's another component called ToastMessage that receives a message prop and has the type of ToastMessageData:
interface ToastMessageProps {
message: ToastMessageData;
style: React.CSSProperties;
}
const ToastMessage: React.FC<ToastMessageProps> = ({ message, style }) => {
I fell that it is weird to import an interface from a context inside of a component, so there's something wrong going on.
What do you guys recommend?