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

Type error with includes casing - camelCase vs dasherized #9701

Open
Techn1x opened this issue Feb 27, 2025 · 1 comment
Open

Type error with includes casing - camelCase vs dasherized #9701

Techn1x opened this issue Feb 27, 2025 · 1 comment

Comments

@Techn1x
Copy link

Techn1x commented Feb 27, 2025

Just bumped into a types issue with includes for requests - typescript seems to be wanting these include fields to be camelCased like schoolClasses and teacherSubscriptions, but my API expects them as dasherized.

Reading the JSONAPI spec https://jsonapi.org/format/#fetching-includes I can see that it seems to use camelCase for its examples, so it might very well be that my API is not to spec in this regard - though in my interpretation of the spec is that it does allow dasherized relationship paths. But difficult to know for sure

Regardless, is there a way I can handle this other than suppressing the type errors on all my includes calls?

Image

@github-project-automation github-project-automation bot moved this to needs triage in EmberData Feb 27, 2025
@Techn1x Techn1x changed the title Type error with includes casing Type error with includes casing - camelCase vs dasherized Feb 27, 2025
@runspired
Copy link
Contributor

the JSON:API rule is that includes have to be valid relationship paths. This gets somewhat weird when the api give you dasherized member names, which are exceedingly difficult to use in javascript, and thus on your model (or in your schema) you utilize camelCase member names instead and transform the response.

We follow the JSON:API rule with the type helper with the expectation that any includes that disobey this rule require a ts-expect-error. That your API's format is dasherized member names while your App's format is camelCase member names is why this turns into friction, because the rule is evaluating the App's version.

Workarounds include:

  • write a query util that doesn't attempt to type-check the relationship paths listed in includes
  • use dasherized member names in your code (ick)
  • update your API to use camelCase member names so that it is more JS friendly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: needs triage
Development

No branches or pull requests

2 participants