Skip to content

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

@wedgberto

Description

@wedgberto

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'."

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions