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

BUG: EntityApiClient<TEntity, T>.getAll() has incorrect return type #54

Open
alexpotterob opened this issue Oct 10, 2023 · 0 comments
Open
Labels
bug Something isn't working

Comments

@alexpotterob
Copy link

It seems the TypeScript return type definition for getAll() is not quite right.

Description

If I do something like:

const apiClient = new ExampleApiClient() // some class that extends EntityApiClient<TEntity, T> (e.g. ExampleApiClient<ExampleEntity, string>)
const apiData = ref<PagedList<ExampleEntity>>(new PagedList<ExampleEntity>());

//... later on in <script setup>
onMounted(async () => {
  apiData.value = await apiClient.getAll(); // error: Types of property "data" are incompatible. ts(2322)
});

After digging, I inspected the actual result of the API call:

const apiClient = new ExampleApiClient() // some class that extends EntityApiClient<TEntity, T> (e.g. ExampleApiClient<ExampleEntity, string>)
const apiResponse = await apiClient.getAll(); // getAll() returns a Promise<PagedList<string>>, according to TS
debugger; // value of apiResponse is actually PagedList<ExampleEntity> when this line is hit at runtime

So it appears that this bug doesn't cause any issues at runtime but it causes a TypeScript type check error (that will probably fail CI)

Expected Behavior

The return type of getAll() should be Promise<PagedList<TEntity>>, like the other methods in the class

Actual Behavior

The return type of getAll() is Promise<PagedList<T>>, where T is the type of the ID of the "entity"

Possible Fix

Change the return type - at runtime we don't see any issue, but we get a TS compiler error

Steps to Reproduce

See description for example code

Context

I was trying to get all entities without paging and came across this error

Your Environment

  • Environment name and version: Chrome 117, nodejs v20.7.0
  • Operating System and version: Windows 10 Pro 22H2 19045.3448
  • TypeScript version: 4.9.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant