Skip to content

Interface vs Types [Typescript] #88

Discussion options

You must be logged in to vote

I suggest:

  • interface for components props
  • types for everything else

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 {

Replies: 4 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@geekonthemove
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@yukinoda
Comment options

Answer selected by jacksonjp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants