Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d84f78e

Browse filesBrowse files
committed
Added tutorial on Set
1 parent 9f4cd6e commit d84f78e
Copy full SHA for d84f78e

File tree

2 files changed

+46
-0
lines changed
Filter options

2 files changed

+46
-0
lines changed

‎src/10-set.problem.ts

Copy file name to clipboard
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { expect, it } from "vitest";
2+
import { Equal, Expect } from "./helpers/type-utils";
3+
4+
const guitarists = new Set();
5+
6+
guitarists.add("Jimi Hendrix");
7+
guitarists.add("Eric Clapton");
8+
9+
it("Should contain Jimi and Eric", () => {
10+
expect(guitarists.has("Jimi Hendrix")).toEqual(true);
11+
expect(guitarists.has("Eric Clapton")).toEqual(true);
12+
});
13+
14+
it("Should give a type error when you try to pass a non-string", () => {
15+
// @ts-expect-error
16+
guitarists.add(2);
17+
});
18+
19+
it("Should be typed as an array of strings", () => {
20+
const guitaristsAsArray = Array.from(guitarists);
21+
22+
type cases = [Expect<Equal<typeof guitaristsAsArray, string[]>>];
23+
});

‎src/10-set.solution.ts

Copy file name to clipboard
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { expect, it } from "vitest";
2+
import { Equal, Expect } from "./helpers/type-utils";
3+
4+
const guitarists = new Set<string>();
5+
6+
guitarists.add("Jimi Hendrix");
7+
guitarists.add("Eric Clapton");
8+
9+
it("Should contain Jimi and Eric", () => {
10+
expect(guitarists.has("Jimi Hendrix")).toEqual(true);
11+
expect(guitarists.has("Eric Clapton")).toEqual(true);
12+
});
13+
14+
it("Should give a type error when you try to pass a non-string", () => {
15+
// @ts-expect-error
16+
guitarists.add(2);
17+
});
18+
19+
it("Should be typed as an array of strings", () => {
20+
const guitaristsAsArray = Array.from(guitarists);
21+
22+
type cases = [Expect<Equal<typeof guitaristsAsArray, string[]>>];
23+
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.