Skip to content

Commit 4d32828

Browse files
committed
Fix TypeScript compilation errors in monorepo template
1 parent d88d803 commit 4d32828

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

.changeset/blue-trees-draw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"create-effect-app": patch
3+
---
4+
5+
Fix TypeScript compilation errors in monorepo template

templates/monorepo/packages/cli/src/Cli.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { Args, Command, Options } from "@effect/cli"
2+
import { TodoId } from "@template/domain/TodosApi"
23
import { TodosClient } from "./TodosClient.js"
34

45
const todoArg = Args.text({ name: "todo" }).pipe(
56
Args.withDescription("The message associated with a todo")
67
)
78

8-
const todoId = Options.integer("id").pipe(
9+
const todoId = Options.withSchema(Options.integer("id"), TodoId).pipe(
910
Options.withDescription("The identifier of the todo")
1011
)
1112

templates/monorepo/packages/cli/src/TodosClient.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { HttpApiClient } from "@effect/platform"
2+
import type { TodoId } from "@template/domain/TodosApi"
23
import { TodosApi } from "@template/domain/TodosApi"
34
import { Effect } from "effect"
45

@@ -19,14 +20,14 @@ export class TodosClient extends Effect.Service<TodosClient>()("cli/TodosClient"
1920
Effect.flatMap((todos) => Effect.logInfo(todos))
2021
)
2122

22-
function complete(id: number) {
23+
function complete(id: TodoId) {
2324
return client.todos.completeTodo({ path: { id } }).pipe(
2425
Effect.flatMap((todo) => Effect.logInfo("Marked todo completed: ", todo)),
2526
Effect.catchTag("TodoNotFound", () => Effect.logError(`Failed to find todo with id: ${id}`))
2627
)
2728
}
2829

29-
function remove(id: number) {
30+
function remove(id: TodoId) {
3031
return client.todos.removeTodo({ path: { id } }).pipe(
3132
Effect.flatMap(() => Effect.logInfo(`Deleted todo with id: ${id}`)),
3233
Effect.catchTag("TodoNotFound", () => Effect.logError(`Failed to find todo with id: ${id}`))

templates/monorepo/packages/domain/src/TodosApi.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export class TodosApiGroup extends HttpApiGroup.make("todos")
2424
HttpApiEndpoint.get("getTodoById", "/todos/:id")
2525
.addSuccess(Todo)
2626
.addError(TodoNotFound, { status: 404 })
27-
.setPath(Schema.Struct({ id: Schema.NumberFromString }))
27+
.setPath(Schema.Struct({ id: TodoIdFromString }))
2828
)
2929
.add(
3030
HttpApiEndpoint.post("createTodo", "/todos")
@@ -35,13 +35,13 @@ export class TodosApiGroup extends HttpApiGroup.make("todos")
3535
HttpApiEndpoint.patch("completeTodo", "/todos/:id")
3636
.addSuccess(Todo)
3737
.addError(TodoNotFound, { status: 404 })
38-
.setPath(Schema.Struct({ id: Schema.NumberFromString }))
38+
.setPath(Schema.Struct({ id: TodoIdFromString }))
3939
)
4040
.add(
4141
HttpApiEndpoint.del("removeTodo", "/todos/:id")
4242
.addSuccess(Schema.Void)
4343
.addError(TodoNotFound, { status: 404 })
44-
.setPath(Schema.Struct({ id: Schema.NumberFromString }))
44+
.setPath(Schema.Struct({ id: TodoIdFromString }))
4545
)
4646
{}
4747

templates/monorepo/packages/server/src/TodosRepository.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class TodosRepository extends Effect.Service<TodosRepository>()("api/Todo
99
Effect.map((todos) => Array.from(HashMap.values(todos)))
1010
)
1111

12-
function getById(id: number): Effect.Effect<Todo, TodoNotFound> {
12+
function getById(id: TodoId): Effect.Effect<Todo, TodoNotFound> {
1313
return Ref.get(todos).pipe(
1414
Effect.flatMap(HashMap.get(id)),
1515
Effect.catchTag("NoSuchElementException", () => new TodoNotFound({ id }))
@@ -18,20 +18,20 @@ export class TodosRepository extends Effect.Service<TodosRepository>()("api/Todo
1818

1919
function create(text: string): Effect.Effect<Todo> {
2020
return Ref.modify(todos, (map) => {
21-
const id = TodoId.make(HashMap.reduce(map, 0, (max, todo) => todo.id > max ? todo.id : max))
21+
const id = TodoId.make(HashMap.reduce(map, -1, (max, todo) => todo.id > max ? todo.id : max) + 1)
2222
const todo = new Todo({ id, text, done: false })
2323
return [todo, HashMap.set(map, id, todo)]
2424
})
2525
}
2626

27-
function complete(id: number): Effect.Effect<Todo, TodoNotFound> {
27+
function complete(id: TodoId): Effect.Effect<Todo, TodoNotFound> {
2828
return getById(id).pipe(
2929
Effect.map((todo) => new Todo({ ...todo, done: true })),
3030
Effect.tap((todo) => Ref.update(todos, HashMap.set(todo.id, todo)))
3131
)
3232
}
3333

34-
function remove(id: number): Effect.Effect<void, TodoNotFound> {
34+
function remove(id: TodoId): Effect.Effect<void, TodoNotFound> {
3535
return getById(id).pipe(
3636
Effect.flatMap((todo) => Ref.update(todos, HashMap.remove(todo.id)))
3737
)

0 commit comments

Comments
 (0)