Skip to content

Commit 393d7f4

Browse files
committed
Changed solution of 32
1 parent 0b79d2b commit 393d7f4

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed
Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import { expect, it } from "vitest";
22
import { Equal, Expect } from "../helpers/type-utils";
33

4-
const fetchData = async <TResult>(
5-
url: string,
6-
): Promise<
7-
unknown extends TResult
8-
? "You must pass a type argument to fetchData"
9-
: TResult
10-
> => {
4+
const fetchData = async <
5+
TResult = "You must pass a type argument to fetchData"
6+
>(
7+
url: string
8+
): Promise<TResult> => {
119
const data = await fetch(url).then((response) => response.json());
1210
return data;
1311
};
1412

1513
it("Should fetch data from an API", async () => {
1614
const data = await fetchData<{ name: string }>(
17-
"https://swapi.dev/api/people/1",
15+
"https://swapi.dev/api/people/1"
1816
);
1917
expect(data.name).toEqual("Luke Skywalker");
2018

@@ -25,6 +23,6 @@ it("Should force you to add a type annotation", async () => {
2523
const data = await fetchData("https://swapi.dev/api/people/1");
2624

2725
type tests = [
28-
Expect<Equal<typeof data, "You must pass a type argument to fetchData">>,
26+
Expect<Equal<typeof data, "You must pass a type argument to fetchData">>
2927
];
3028
});

0 commit comments

Comments
 (0)