From c7470e3fe726d50c96423532ca515c68225f3fd9 Mon Sep 17 00:00:00 2001 From: hamed-zeidabadi Date: Sat, 8 Nov 2025 08:55:14 +0330 Subject: [PATCH] fix: improve type safety in TutorialDataService Replace 'any' type with proper types for better type safety: - Change id parameter type from 'any' to 'string' in update() and delete() - Change update() return type from 'any' to 'ITutorialData' - Reorder update() parameters to (id, data) for consistency with REST conventions - Update component calls to match new parameter order This improves type safety and prevents potential runtime errors from incorrect parameter types. --- src/components/tutorial.component.tsx | 8 ++++---- src/services/tutorial.service.ts | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/components/tutorial.component.tsx b/src/components/tutorial.component.tsx index 5cf17a9..656218a 100644 --- a/src/components/tutorial.component.tsx +++ b/src/components/tutorial.component.tsx @@ -85,7 +85,7 @@ export default class Tutorial extends Component { published: status, }; - TutorialDataService.update(data, this.state.currentTutorial.id) + TutorialDataService.update(this.state.currentTutorial.id!, data) .then((response: any) => { this.setState((prevState) => ({ currentTutorial: { @@ -103,8 +103,8 @@ export default class Tutorial extends Component { updateTutorial() { TutorialDataService.update( - this.state.currentTutorial, - this.state.currentTutorial.id + this.state.currentTutorial.id!, + this.state.currentTutorial ) .then((response: any) => { console.log(response.data); @@ -118,7 +118,7 @@ export default class Tutorial extends Component { } deleteTutorial() { - TutorialDataService.delete(this.state.currentTutorial.id) + TutorialDataService.delete(this.state.currentTutorial.id!) .then((response: any) => { console.log(response.data); this.props.history.push("/tutorials"); diff --git a/src/services/tutorial.service.ts b/src/services/tutorial.service.ts index ea3b141..2c8f893 100644 --- a/src/services/tutorial.service.ts +++ b/src/services/tutorial.service.ts @@ -14,11 +14,11 @@ class TutorialDataService { return http.post("/tutorials", data); } - update(data: ITutorialData, id: any) { - return http.put(`/tutorials/${id}`, data); + update(id: string, data: ITutorialData) { + return http.put(`/tutorials/${id}`, data); } - delete(id: any) { + delete(id: string) { return http.delete(`/tutorials/${id}`); }