Skip to content

merge-deep: wrong types inferred when using partial interfaces #1314

@salisbury-espinosa

Description

@salisbury-espinosa

Bug description

the correct operation of this utility depends on the order of types!

Let's say there is interface Pokemon like this:

import type {MergeDeep} from 'type-fest';

interface Pokemon {
      name: string;
      type: string;
    }

valid :

    const testThroughAssert: Pokemon = {} as MergeDeep<
      Partial<Pokemon>,
      Pokemon
    >;

=> success

invalid:

    const testThroughAssert: Pokemon = {} as MergeDeep<
      Pokemon,
      Partial<Pokemon>
    >;

=> error TS2322: Type '{ name?: string | undefined; type?: string | undefined; }' is not assignable to type 'Pokemon'.

Repro

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBDAnmApnA3gWRVA5igERRTAF84AzKCEOAciVQFoKUBnGOgbgFgAofsAB2MHBQCGAYzQAFCAGsUICEIz84GzUPEgUALjgcow3Lz6bNjfYZjGhp9ZtL9+klRwTsYAFQAW1AFdcXwBBNjYcGAM5RWVVAF4McnE2OGw8QmIwAB5HCxilFQAaPM0ZcVhgcQAbbIK4gD5Shq4gA

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions