From 6575bb423896f190de67ad49adfc1fcddde29662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A1bio=20Henriques?= Date: Mon, 28 Aug 2023 14:01:00 +0100 Subject: [PATCH] Add naming conventions for prop types --- .../PROPTYPES_CONVERSION_TABLE.md | 4 ++-- contributingGuides/TS_STYLE.md | 22 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/contributingGuides/PROPTYPES_CONVERSION_TABLE.md b/contributingGuides/PROPTYPES_CONVERSION_TABLE.md index 4ef1cd5ca655..e7584f82a351 100644 --- a/contributingGuides/PROPTYPES_CONVERSION_TABLE.md +++ b/contributingGuides/PROPTYPES_CONVERSION_TABLE.md @@ -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; @@ -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. diff --git a/contributingGuides/TS_STYLE.md b/contributingGuides/TS_STYLE.md index 0d6774792c45..bc62020ffd54 100644 --- a/contributingGuides/TS_STYLE.md +++ b/contributingGuides/TS_STYLE.md @@ -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.