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

Select within an expand on an optional property not compatible with keyof #114

Open
wedgberto opened this issue Apr 5, 2023 · 0 comments

Comments

@wedgberto
Copy link

wedgberto commented Apr 5, 2023

In this sample, Expand is not able to check that each entry in the select array is a key of the optional maybe property of the parent type. I'd love to be able to rely on this great library to check that I am only selecting properties that have been defined on my classes/interfaces and not be open to typos.

import { Expand } from 'odata-query';

interface child {
    id: string,
    name: string,
}
interface parent {
    definite: child,
    maybe?: child,
}

const compiles_with_a_definite_property: Expand<parent> = {
    definite: {
        select: ['id', 'name'],
    },
};

const does_not_compile_but_I_want_the_key_check: Expand<parent> = {
    maybe: {
        select: ['id', 'name'],
    },
};

const compiles_but_not_safe: Expand<parent> = {
    maybe: {
        select: 'id,naem,property_name_that_is_not_in_the_data_source,you_get_the_idea,api_wont_like_it',
    },
};

The majority of the sample has no errors but does_not_compile_but_I_want_the_key_check has the following:

Type '{ maybe: { select: string[]; }; }' is not assignable to type 'Expand'.
The types of 'maybe.select' are incompatible between these types.
Type 'string[]' is not assignable to type 'Select<child | undefined> | undefined'.
Type 'string[]' is not assignable to type 'never[]'.
Type 'string' is not assignable to type 'never'."

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

No branches or pull requests

1 participant