Skip to content

Commit d9c9735

Browse files
committed
chore: add typings for jsonplaceholder
1 parent 031754d commit d9c9735

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

angular-17/main.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { HttpClient, provideHttpClient } from "@angular/common/http";
66
import { Component, effect, inject, Injectable, signal } from "@angular/core";
77
import { toSignal } from "@angular/core/rxjs-interop";
88
import { bootstrapApplication } from "@angular/platform-browser";
9+
import type { User } from "jsonplaceholder-types/types/user";
10+
import type { Post } from "jsonplaceholder-types/types/post";
911

1012
@Injectable({ providedIn: "root" })
1113
class AppService {
@@ -14,11 +16,11 @@ class AppService {
1416
readonly #httpClient = inject(HttpClient);
1517

1618
getUsers() {
17-
return this.#httpClient.get(`${AppService.#urlBase}/users`);
19+
return this.#httpClient.get<User[]>(`${AppService.#urlBase}/users`);
1820
}
1921

2022
getPosts(userId: number) {
21-
return this.#httpClient.get(`${AppService.#urlBase}/posts`, {
23+
return this.#httpClient.get<Post[]>(`${AppService.#urlBase}/posts`, {
2224
params: { userId },
2325
});
2426
}

angular-21/main.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,19 @@ import {
1212
} from "@angular/core";
1313
import { Field, form } from "@angular/forms/signals";
1414
import { bootstrapApplication } from "@angular/platform-browser";
15+
import type { User } from "jsonplaceholder-types/types/user";
16+
import type { Post } from "jsonplaceholder-types/types/post";
1517

1618
@Injectable({ providedIn: "root" })
1719
class AppService {
1820
static readonly #urlBase = "https://jsonplaceholder.typicode.com";
1921

2022
getUsers() {
21-
return httpResource(() => `${AppService.#urlBase}/users`);
23+
return httpResource<User[]>(() => `${AppService.#urlBase}/users`);
2224
}
2325

2426
getPosts(userIdSignal: Signal<string | undefined>) {
25-
return httpResource(() => {
27+
return httpResource<Post[]>(() => {
2628
const userId = userIdSignal();
2729
if (userId == undefined) return undefined;
2830
return {

deno.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"workspace": ["./angular-*"],
3+
"imports": {
4+
"jsonplaceholder-types/": "https://esm.sh/*jsonplaceholder-types@1.0.2&dev/"
5+
}
6+
}

0 commit comments

Comments
 (0)