balena-io-modules / odata-parser

4 stars 1 forks source link

odata-parser.d.ts causing eslint problems #79

Open haihovu opened 3 months ago

haihovu commented 3 months ago

We use @balena/odata-parser in one of our projects, and the transpiler tsc is complaining about these:

node_modules/@balena/odata-parser/odata-parser.d.ts:57:2 - error TS2411: Property '$select' of type 'SelectOption | undefined' is not assignable to 'string' index type 'string | number | boolean | NumberBind | BooleanBind | TextBind | DateBind | { properties: PropertyPat
h[]; } | ExpandOption | OrderByOption | { ...; }'.

57  $select?: SelectOption;
    ~~~~~~~
...

Looking at odata-parser.d.ts I can see that ODataOptions was defined as:


export interface ODataOptions {
    $select?: SelectOption;
    $filter?: FilterOption;
    $expand?: ExpandOption;
    $orderby?: OrderByOption;
    $top?: number;
    $skip?: number;
    $count?: boolean;
    $inlinecount?: string;
    $format?: FormatOption;

    [key: string]: // User defined options, do not start with $ or @
    | string
        // Parameter aliases (start with @)
        | NumberBind
        | BooleanBind
        | TextBind
        | DateBind
        // known $ options
        | SelectOption
        | ExpandOption
        | OrderByOption
        | FormatOption
        | number
        | boolean;
}

Note that all properties are optional, and as such the part below should include a undefined as follows:

export interface ODataOptions {
    $select?: SelectOption;
    $filter?: FilterOption;
    $expand?: ExpandOption;
    $orderby?: OrderByOption;
    $top?: number;
    $skip?: number;
    $count?: boolean;
    $inlinecount?: string;
    $format?: FormatOption;

    [key: string]: // User defined options, do not start with $ or @
    | string
        // Parameter aliases (start with @)
        | NumberBind
        | BooleanBind
        | TextBind
        | DateBind
        // known $ options
        | SelectOption
        | ExpandOption
        | OrderByOption
        | FormatOption
        | number
        | boolean
                | undefined; <--- This is needed
}

If I made that change in the d.ts tsc was happy.

haihovu commented 3 months ago

In order to get around this we currently have to use const parser = require('@balena/odata-parser') instead of import {parse} from '@balena/odata-parser'.