We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6d591dd commit edb0693Copy full SHA for edb0693
src/02-passing-type-arguments/11-data-fetcher.solution.ts
@@ -1,14 +1,15 @@
1
import { expect, it } from "vitest";
2
import { Equal, Expect } from "../helpers/type-utils";
3
4
-const fetchData = async <TResult>(url: string): Promise<TResult> => {
5
- const data = await fetch(url).then((response) => response.json());
+const fetchData = async <TData>(url: string) => {
+ let data: TData = await fetch(url).then((response) => response.json());
6
+
7
return data;
8
};
9
10
it("Should fetch data from an API", async () => {
11
const data = await fetchData<{ name: string }>(
- "https://swapi.dev/api/people/1",
12
+ "https://swapi.dev/api/people/1"
13
);
14
expect(data.name).toEqual("Luke Skywalker");
15
0 commit comments