Skip to content

Intersection with type parameter doesn't subtract properties #20536

Closed
@smoogly

Description

@smoogly

TypeScript Version: 2.6.1 && 2.7.0-dev.20171207

Code

interface InternalProps {
    a: number;
}
interface ExternalProps {
    b: string;
}

function make<T = {}>(arg: T & InternalProps): T & ExternalProps {
    return 1 as any;
}

const x = make<{}>({a: 1});
console.log(x.a); // Correct: type error

const y = make({a: 1});
console.log(y.a); // Incorrect: no type error

Expected behavior:
Property a should not be expected to exist on y.
Both examples should fail.

Actual behavior:
Only first example is considered a type error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Working as IntendedThe behavior described is the intended behavior; this is not a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions