Skip to content

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

@alexpotterob

Description

@alexpotterob

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions