Skip to content

Commit 148c697

Browse files
committed
Add documentation to typescript.md for when to declare a type on variables
1 parent e36b2ba commit 148c697

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

docs/typescript.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,24 @@ When we reach the moment where the entire codebase is in TS, we will enable `noI
99

1010
This is just starting, any suggestion is always welcomed and appreciated.
1111

12+
## Declaring types for variables
13+
14+
When declaring types for variables, you should only declare a type when it isn't obvious and the type can't be inferred.
15+
16+
```
17+
// Do not use
18+
const someVar: string = 'string'
19+
20+
// Use
21+
const someVar = 'string'
22+
```
23+
24+
Do declare a type for an unassigned variable when a type can not be inferred.
25+
26+
```
27+
const someVar: string
28+
```
29+
1230
## Migration guide & contribution opportunity 🎉
1331

1432
We'd love your help in migrating our codebase!

0 commit comments

Comments
 (0)