mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Doc: Add rule "Do not set the type when it can be inferred"
This commit is contained in:
parent
f116504e88
commit
16d8a78d8a
@ -52,6 +52,28 @@ const config: Config = {
|
||||
}
|
||||
```
|
||||
|
||||
### Don't set the type when it can be inferred
|
||||
|
||||
TypeScript can automatically detect the type so setting it explicitely in many cases is not needed, and makes the code unecessary verbose. We already have enabled the eslint rule `no-inferrable-types`, however it only applies to simple types such as string, number, etc. but not to function calls.
|
||||
|
||||
**BAD:**
|
||||
```ts
|
||||
const getSomething():string => {
|
||||
return 'something';
|
||||
}
|
||||
|
||||
const timestamp:number = Date.now();
|
||||
```
|
||||
|
||||
**Good:**
|
||||
```ts
|
||||
const getSomething() => {
|
||||
return 'something';
|
||||
}
|
||||
|
||||
const timestamp = Date.now();
|
||||
```
|
||||
|
||||
## Filenames
|
||||
|
||||
* `camelCase.ts`: Files that export multiple things.
|
||||
|
Loading…
Reference in New Issue
Block a user