Skip to content

Inference from variable reference produces different type argument #2321

@dragomirtitian

Description

@dragomirtitian

Steps to reproduce

declare const deepEqual: <T>(actualValue: T, expectedValue: T, message?: string) => void;

const actualValue = { a: "hello", b: undefined, c: "world", d: undefined };
// Fails in ts-go
deepEqual(actualValue, {
    a: "hello",
    c: "world",
});

// Works in both
deepEqual({ a: "hello", b: undefined, c: "world", d: undefined }, {
    a: "hello",
    c: "world",
});

Playground Link

Behavior with typescript@5.9

Both calls type check

Behavior with tsgo

First call fails to type check with:

src/index.ts:5:24 - error TS2739: Type '{ a: string; c: string; }' is missing the following properties from type '{ a: string; b: undefined; c: string; d: undefined; }': b, d

5 deepEqual(actualValue, {
                         ~
6     a: "hello",
  ~~~~~~~~~~~~~~~
7     c: "world",
  ~~~~~~~~~~~~~~~
8 });

Metadata

Metadata

Assignees

No one assigned

    Labels

    Domain: Type CheckingRelated to type checking, grammar checking

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions