Interface vs Types [Typescript] #88
-
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
This may one good way when thinking of using which one 🤔 |
Beta Was this translation helpful? Give feedback.
-
Nice article discussing interface vs types |
Beta Was this translation helpful? Give feedback.
-
info: |
Beta Was this translation helpful? Give feedback.
-
I suggest:
so as an example: // could be defined in a file like `types/user.types.ts`
type UserDef = {
name: string;
}
// in a file like `UserProfile.tsx`
interface UserProfileProps {
user: UserDef;
}
const UserProfile = ({ user }: UserProfileProps) => {
return <div>{user.name}</div>;
} Reason, other than it being a personal preference, I think it makes it easy to read if we want to extend our component props, for example: interface UserProfileProps extends CardProps { |
Beta Was this translation helpful? Give feedback.
I suggest:
so as an example:
Reason, other than it being a personal preference, I think it makes it easy to read if we want to extend our component props, for example: