Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/10-set.solution.2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { expect, it } from "vitest";
import { Equal, Expect } from "./helpers/type-utils";

const guitarists: Set<string> = new Set();

guitarists.add("Jimi Hendrix");
guitarists.add("Eric Clapton");

it("Should contain Jimi and Eric", () => {
expect(guitarists.has("Jimi Hendrix")).toEqual(true);
expect(guitarists.has("Eric Clapton")).toEqual(true);
});

it("Should give a type error when you try to pass a non-string", () => {
// @ts-expect-error
guitarists.add(2);
});

it("Should be typed as an array of strings", () => {
const guitaristsAsArray = Array.from(guitarists);

type tests = [Expect<Equal<typeof guitaristsAsArray, string[]>>];
});