Skip to content

Strict object literal check fails when infered to type containing string literal type #7085

Closed
@erichillah

Description

@erichillah

Hi,
This issue might be linked to #6167 ( particularly widening i guess) or #6554, but i did not find any details the bellow case:

interface Test {
    value: string;
    comparator:"equals"|"isGreater";
}

function applyTest(value: string, testval:Test) {
    return "ok";
}

let tt = {value: "test", comparator:"equals"};
applyTest("ko",tt);

when i compile using tsc ([email protected]) i get a warning

test.ts(11,16): error TS2345: Argument of type '{ value: string; comparator: string; }' is not assignable to parameter of type 'Test'.
  Types of property 'comparator' are incompatible.
    Type 'string' is not assignable to type '"equals" | "isGreater"'.
      Type 'string' is not assignable to type '"isGreater"'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions