Skip to content

Commit

Permalink
Add naming conventions for prop types
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioh8010 committed Aug 28, 2023
1 parent 9819021 commit 6575bb4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions contributingGuides/PROPTYPES_CONVERSION_TABLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const propTypes = {
};

// After
type Props = {
type ComponentProps = {
isVisible: boolean;
// Consider it as required unless you have proof that it is indeed an optional prop.
confirmText: string; // vs. confirmText?: string;
Expand Down Expand Up @@ -115,7 +115,7 @@ type Input = {

type Size = "small" | "medium" | "large";

type Props = {
type ComponentProps = {
unknownData: string[];

// It's not possible to infer the data as it can be anything because of reasons X, Y and Z.
Expand Down
22 changes: 22 additions & 0 deletions contributingGuides/TS_STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,28 @@ type Foo = {
type Color = "red" | "blue" | "green";
```

- Use `{ComponentName}Props` pattern for prop types.

```ts
// BAD
type Props = {
// component's props
};
function MyComponent({}: Props) {
// component's code
}
// GOOD
type MyComponentProps = {
// component's props
};
function MyComponent({}: MyComponentProps) {
// component's code
}
```

- For generic type parameters, use `T` if you have only one type parameter. Don't use the `T`, `U`, `V`... sequence. Make type parameter names descriptive, each prefixed with `T`.

> Prefix each type parameter name to distinguish them from other types.
Expand Down

0 comments on commit 6575bb4

Please sign in to comment.