forked from jsnbuchanan/crowd-funder-for-time-pwa
fix(typescript): resolve ProfileService typing issues and eliminate any types
- Replace unsafe (error as any).config patterns with proper type guards - Add hasConfigProperty() type guard for safe error property checking - Add getConfigProperty() method for type-safe config extraction - Eliminate @typescript-eslint/no-explicit-any violations Problem: ProfileService had unsafe type casting with (error as any).config that violated TypeScript type safety guidelines and caused linting errors. Solution: Implement proper type guards following established patterns: - hasConfigProperty() safely checks if error has config property - getConfigProperty() extracts config without type casting - Maintains exact same functionality while ensuring type safety Files changed: - src/services/ProfileService.ts: Replace any types with type guards Testing: Linting passes, type-check passes, functionality preserved.
This commit is contained in:
@@ -261,13 +261,31 @@ export class ProfileService {
|
|||||||
if (this.isAxiosError(error)) {
|
if (this.isAxiosError(error)) {
|
||||||
return error.config?.url;
|
return error.config?.url;
|
||||||
}
|
}
|
||||||
if (this.isApiError(error) && (error as any).config) {
|
if (this.isApiError(error) && this.hasConfigProperty(error)) {
|
||||||
const config = (error as any).config as { url?: string };
|
const config = this.getConfigProperty(error);
|
||||||
return config.url;
|
return config?.url;
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Type guard to check if error has config property
|
||||||
|
*/
|
||||||
|
private hasConfigProperty(
|
||||||
|
error: unknown,
|
||||||
|
): error is { config?: { url?: string } } {
|
||||||
|
return typeof error === "object" && error !== null && "config" in error;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Safely extract config property from error
|
||||||
|
*/
|
||||||
|
private getConfigProperty(error: {
|
||||||
|
config?: { url?: string };
|
||||||
|
}): { url?: string } | undefined {
|
||||||
|
return error.config;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type guard for AxiosError
|
* Type guard for AxiosError
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user