Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Review use of as unknown as in mutate-request.ts #1466

Open
samayer12 opened this issue Nov 20, 2024 · 0 comments
Open

Review use of as unknown as in mutate-request.ts #1466

samayer12 opened this issue Nov 20, 2024 · 0 comments

Comments

@samayer12
Copy link
Collaborator

Describe what should be investigated or refactored

Some typing is circumvented with the use of as unknown as in mutate-request.ts. We must determine if this is truly necessary.

TypeScript is designed to catch type errors at compile time. Using as unknown as effectively bypasses TypeScript's checks. We're telling the compiler to trust the type assertion, even if the types are incompatible, which can lead to runtime errors. This could also indicate Poorly structured type hierarchies, incomplete or incorrect type definitions, and/or a lack of proper handling of the actual types involved.

In most cases, we can use a better alternative such as:

  • Refactor type definitions to accurately represent the data.
  • Use type guards or user-defined type predicates to refine types safely.
  • Use utility types like Partial or Omit to handle flexible or partial structures.

Links to any relevant code

Additional context

It's possible that no better alternative exists. If so, leave a comment on this issue or write an ADR on the use of as unknown as so that we have record of why the code is the way it is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🆕 New
Development

No branches or pull requests

1 participant