Skip to content

Commit f59b25c

Browse files
committed
In code blocks, prefer full language name over abbreviation
1 parent 6e3a689 commit f59b25c

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

docs/typescript.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ There are several reasons for this:
2525

2626
🚫 Type declarations
2727

28-
```ts
28+
```typescript
2929
const name: string = 'METAMASK'; // Type 'string'
3030

3131
const BUILT_IN_NETWORKS = new Map<string, `0x${string}`>([
@@ -36,7 +36,7 @@ const BUILT_IN_NETWORKS = new Map<string, `0x${string}`>([
3636

3737
✅ Type inferences
3838

39-
```ts
39+
```typescript
4040
const name = 'METAMASK'; // Type 'METAMASK'
4141

4242
const BUILT_IN_NETWORKS = {
@@ -47,7 +47,7 @@ const BUILT_IN_NETWORKS = {
4747

4848
#### Example: To annotate or not to annotate
4949

50-
```ts
50+
```typescript
5151
type TransactionMeta = TransactionBase &
5252
(
5353
| {
@@ -73,7 +73,7 @@ this.messagingSystem.publish(
7373

7474
🚫 Add type annotation
7575

76-
```ts
76+
```typescript
7777
// Type 'TransactionMeta'
7878
const updatedTransactionMeta: TransactionMeta = {
7979
...transactionMeta,
@@ -83,7 +83,7 @@ const updatedTransactionMeta: TransactionMeta = {
8383

8484
✅ Add `as const` and leave to inference
8585

86-
```ts
86+
```typescript
8787
// Type narrower than 'TransactionMeta': { status: TransactionStatus.rejected; ... }
8888
// (doesn't include 'error' property)
8989
const updatedTransactionMeta = {
@@ -104,15 +104,15 @@ There is a clear exception to the above: if an explicit type annotation or asser
104104
105105
🚫
106106

107-
```ts
107+
```typescript
108108
const chainId: string = this.messagingSystem(
109109
'NetworkController:getProviderConfig',
110110
).chainId; // Type 'string'
111111
```
112112

113113
114114

115-
```ts
115+
```typescript
116116
const chainId = this.messagingSystem(
117117
'NetworkController:getProviderConfig',
118118
).chainId; // Type '`0x${string}`'
@@ -124,14 +124,14 @@ This is one case where type inference is unable to reach a useful conclusion wit
124124

125125
🚫
126126

127-
```ts
127+
```typescript
128128
const tokens = []; // Type 'any[]'
129129
const tokensMap = new Map(); // Type 'Map<any, any>'
130130
```
131131

132132
133133

134-
```ts
134+
```typescript
135135
const tokens: string[] = []; // Type 'string[]'
136136
const tokensMap = new Map<string, Token>(); // Type 'Map<string, Token>'
137137
```
@@ -140,7 +140,7 @@ const tokensMap = new Map<string, Token>(); // Type 'Map<string, Token>'
140140

141141
<!-- TODO: Add explanation and examples -->
142142

143-
```ts
143+
```typescript
144144
function isSomeInterface(x: unknown): x is SomeInterface {
145145
return (
146146
'name' in x &&
@@ -211,7 +211,7 @@ Otherwise, only mocking the properties needed in the test improves readability b
211211

212212
<!-- TODO: Add examples -->
213213

214-
```ts
214+
```typescript
215215
const handler:
216216
| ((payload_0: ComposableControllerState, payload_1: Patch[]) => void)
217217
| ((payload_0: any, payload_1: Patch[]) => void); // Type of 'payload_0': 'any'
@@ -236,7 +236,7 @@ Some generic types use `any` as a default generic argument. This can silently in
236236

237237
🚫
238238

239-
```ts
239+
```typescript
240240
const NETWORKS = new Map({
241241
mainnet: '0x1',
242242
goerli: '0x5',
@@ -251,7 +251,7 @@ mockGetNetworkConfigurationByNetworkClientId.mockImplementation(
251251

252252
253253

254-
```ts
254+
```typescript
255255
const NETWORKS = new Map<string, `0x${string}`>({
256256
mainnet: '0x1',
257257
goerli: '0x5',
@@ -276,7 +276,7 @@ In most type errors involving property access or runtime property assignment, `a
276276

277277
🚫
278278

279-
```ts
279+
```typescript
280280
for (const key of getKnownPropertyNames(this.internalConfig)) {
281281
(this as any)[key] = this.internalConfig[key];
282282
}
@@ -288,7 +288,7 @@ delete addressBook[chainId as any];
288288

289289
290290

291-
```ts
291+
```typescript
292292
for (const key of getKnownPropertyNames(this.config)) {
293293
(this as unknown as typeof this.config)[key] = this.config[key];
294294
}
@@ -300,20 +300,20 @@ However, when assigning to a generic type, using `as any` is the only solution.
300300

301301
🚫
302302

303-
```ts
303+
```typescript
304304
(state as RateLimitState<RateLimitedApis>).requests[api][origin] = previous + 1;
305305
// is generic and can only be indexed for reading.ts(2862)
306306
```
307307

308308
309309

310-
```ts
310+
```typescript
311311
(state as any).requests[api][origin] = previous + 1;
312312
```
313313

314314
Even in this case, however, `any` usage might be avoidable by using `Object.assign` or spread operator syntax instead of assignment.
315315

316-
```ts
316+
```typescript
317317
Object.assign(state, {
318318
requests: {
319319
...state.requests,
@@ -334,7 +334,7 @@ Object.assign(state, {
334334

335335
336336

337-
```ts
337+
```typescript
338338
class BaseController<
339339
...,
340340
messenger extends RestrictedControllerMessenger<N, any, any, string, string>
@@ -362,7 +362,7 @@ Although TypeScript is capable of inferring return types, adding them explicitly
362362

363363
🚫
364364

365-
```ts
365+
```typescript
366366
async function removeAccount(address: Hex) {
367367
const keyring = await this.getKeyringForAccount(address);
368368
@@ -379,7 +379,7 @@ async function removeAccount(address: Hex) {
379379

380380
381381

382-
```ts
382+
```typescript
383383
async function removeAccount(address: Hex): Promise<KeyringControllerState> {
384384
const keyring = await this.getKeyringForAccount(address);
385385

0 commit comments

Comments
 (0)