Skip to content

Commit 5682268

Browse files
committed
Fix TypeScript error for symbol comparison and formatting
1 parent d65fd63 commit 5682268

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

exercises/01.primitive-types/04.solution.bigint-and-symbol/index.test.ts

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,41 @@ await testStep('largeNumber should be a bigint', async () => {
1313
typeof largeNumber,
1414
'🚨 largeNumber should be type bigint - use the n suffix: 9007199254740993n',
1515
).toBe('bigint')
16-
expect(
17-
largeNumber,
18-
'🚨 largeNumber should be 9007199254740993n',
19-
).toBe(9007199254740993n)
16+
expect(largeNumber, '🚨 largeNumber should be 9007199254740993n').toBe(
17+
9007199254740993n,
18+
)
2019
})
2120

2221
await testStep('anotherLarge should be a bigint', async () => {
23-
expect(
24-
typeof anotherLarge,
25-
'🚨 anotherLarge should be type bigint',
26-
).toBe('bigint')
27-
expect(
28-
anotherLarge,
29-
'🚨 anotherLarge should be 1000000000000000000n',
30-
).toBe(1000000000000000000n)
22+
expect(typeof anotherLarge, '🚨 anotherLarge should be type bigint').toBe(
23+
'bigint',
24+
)
25+
expect(anotherLarge, '🚨 anotherLarge should be 1000000000000000000n').toBe(
26+
1000000000000000000n,
27+
)
3128
})
3229

3330
await testStep('sum should be the addition of both bigints', async () => {
34-
expect(
35-
typeof sum,
36-
'🚨 sum should be type bigint',
37-
).toBe('bigint')
38-
expect(
39-
sum,
40-
'🚨 sum should be largeNumber + anotherLarge',
41-
).toBe(largeNumber + anotherLarge)
31+
expect(typeof sum, '🚨 sum should be type bigint').toBe('bigint')
32+
expect(sum, '🚨 sum should be largeNumber + anotherLarge').toBe(
33+
largeNumber + anotherLarge,
34+
)
4235
})
4336

4437
await testStep('userId and anotherId should be symbols', async () => {
4538
expect(
4639
typeof userId,
4740
'🚨 userId should be type symbol - use Symbol("user-id")',
4841
).toBe('symbol')
49-
expect(
50-
typeof anotherId,
51-
'🚨 anotherId should be type symbol',
52-
).toBe('symbol')
42+
expect(typeof anotherId, '🚨 anotherId should be type symbol').toBe('symbol')
5343
})
5444

55-
await testStep('symbols with same description should not be equal', async () => {
56-
expect(
57-
areEqual,
58-
'🚨 areEqual should be false - each Symbol() creates a unique value even with the same description',
59-
).toBe(false)
60-
})
45+
await testStep(
46+
'symbols with same description should not be equal',
47+
async () => {
48+
expect(
49+
areEqual,
50+
'🚨 areEqual should be false - each Symbol() creates a unique value even with the same description',
51+
).toBe(false)
52+
},
53+
)

exercises/01.primitive-types/04.solution.bigint-and-symbol/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const sum = largeNumber + anotherLarge
99
// Symbols are unique (TypeScript infers symbol from Symbol())
1010
const userId = Symbol('user-id')
1111
const anotherId = Symbol('user-id')
12+
// @ts-expect-error TypeScript knows these unique symbols are never equal - that's the point!
1213
const areEqual = userId === anotherId // false!
1314

1415
console.log('Large number:', largeNumber)

0 commit comments

Comments
 (0)