Jhernandez has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/373719 )

Change subject: Doc: add typing convention
......................................................................


Doc: add typing convention

Change-Id: I80907347a3da67986ea7055b156faa2ab807b0b5
---
M docs/development.md
1 file changed, 57 insertions(+), 1 deletion(-)

Approvals:
  Jhernandez: Verified; Looks good to me, approved



diff --git a/docs/development.md b/docs/development.md
index 8c6a327..be3f58c 100644
--- a/docs/development.md
+++ b/docs/development.md
@@ -41,7 +41,6 @@
 * To automatically format source code and fix linting errors, you can run:
   * `npm run format`
 
-
 ## Running the production version
 
 If you want to run the production version, then:
@@ -50,3 +49,60 @@
   * `npm run build`
 * Run the production server with:
   * `NODE_ENV=production node dist/server/index.js`
+
+## Coding conventions
+
+### Typing
+
+In TypeScript, data types may be explicitly specified or (often) inferred by 
the
+compiler. Marvin's coding convention is to favor inference except for module
+exports. Another way to phrase this is: write concisely except for APIs. The
+reasoning is that the brevity of inferred code is preferred but APIs are seams
+and their types should be both fixed and documented.
+
+The following examples are possible module implementations but the second or
+third are preferred:
+
+1. Explicitly over-typed (right-hand typing is internal):
+    ```js
+    const app: FunctionalComponent<any> = (_props: any): JSX.Element =>
+      <div class="App">Hello world</div>;
+
+    export default app
+    ```
+
+2. Explicitly typed (declared syntax):
+    ```js
+    const app: FunctionalComponent<any> = () =>
+      <div class="App">Hello world</div>;
+
+    export default app
+    ```
+
+3. Explicitly typed (inline syntax):
+    ```js
+    export default (_props: any): JSX.Element =>
+      <div class="App">Hello world</div>;
+    ```
+
+4. Implicitly typed:
+    ```js
+    export default () =>
+      <div class="App">Hello world</div>;
+    ```
+
+The following are possible internal implementations but the second is 
preferred:
+
+1. Explicitly typed:
+    ```js
+    server.get("*", (_request: express.Request, response: express.Response) => 
{
+      response.status(404).send("Not found");
+    });
+    ```
+
+2. Implicitly typed:
+    ```js
+    server.get("*", (_request, response) => {
+      response.status(404).send("Not found");
+    });
+    ```

-- 
To view, visit https://gerrit.wikimedia.org/r/373719
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I80907347a3da67986ea7055b156faa2ab807b0b5
Gerrit-PatchSet: 1
Gerrit-Project: marvin
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <[email protected]>
Gerrit-Reviewer: Jhernandez <[email protected]>
Gerrit-Reviewer: Niedzielski <[email protected]>
Gerrit-Reviewer: Sniedzielski <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to