diff --git a/contributingGuides/STYLE.md b/contributingGuides/STYLE.md index 304811332916..e6660d848129 100644 --- a/contributingGuides/STYLE.md +++ b/contributingGuides/STYLE.md @@ -24,6 +24,7 @@ - [Refs](#refs) - [Other Expensify Resources on TypeScript](#other-expensify-resources-on-typescript) - [Default value for inexistent IDs](#default-value-for-inexistent-IDs) + - [Extract complex types](#extract-complex-types) - [Naming Conventions](#naming-conventions) - [Type names](#type-names) - [Prop callbacks](#prop-callbacks) @@ -492,6 +493,30 @@ const foo = report?.reportID ?? '-1'; report ? report.reportID : '-1'; ``` +### Extract complex types + +Advanced data types, such as objects within function parameters, should be separated into their own type definitions. Callbacks in function parameters should be extracted if there's a possibility they could be reused somewhere else. + +```ts +// BAD +function foo(param1: string, param2: {id: string}) {...}; + +// BAD +function foo(param1: string, param2: (value: string) => void) {...}; + +// GOOD +type Data = { + id: string; +}; + +function foo(param1: string, param2: Data) {...}; + +// GOOD +type Callback = (value: string) => void + +function foo(param1: string, param2: Callback) {...}; +``` + ## Naming Conventions ### Type names