Skip to content

Inconsistent type inference #16145

Closed
Closed
@ylepikhov

Description

@ylepikhov

TypeScript Version: 2.3.3
See also playground

Code

interface I {

    p: string;
}

class C implements I {

    p: string;
    pp: number;
}

// no error
const c: Partial<C> = { p: "" };

function ff<T extends I>(v: Partial<T>) {

    // no error
    return v.p;
}

function f<T extends I>() {

    // error TS2322: Type '{ p: string; }' is not assignable to type 'Partial<T>'
    // why?
    const t: Partial<T> = { p: "" };
}

Expected behavior:
No error

Actual behavior:
Error at line: const t: Partial<T> = { p: "" };

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions