Skip to content

Weak type detection for intersection types #19296

Closed

Description

TypeScript Version: 2.6.0-dev.20171018

Code

interface X { x: string }
interface Y { y: number }
interface Z { z?: boolean }

type XY = X & Y;
const xy: XY = {x: 'x', y: 10};

const z1: Z = xy;
// (1) compiles without any errors

const z2: Z = xy as Pick<XY, keyof XY>;
// (2) produces error: Type 'Pick<X & Y, "x" | "y">' has no properties in common with type 'Z'.

Expected behavior:
(1) should produce an error similar to (2) because there are no common properties for XY and Z types.

Actual behavior:
(1) compiles without any errors.

Activity

  1. sandersn commented on Aug 24, 2018

    @sandersn
    Member

    I looked at the code and I think the exclusion of intersection sources is a side-effect of the original implementation, which only worked on object types. But it's trivial to allow intersections as source types.

    I didn't see any new errors on the user tests, and on Definitely Typed, only in react-native-sortable-list and react-native-swiper, where we now detect the assignment of a branded number to an object type. The branded number came from a mapped type, so this is a subtle bug, and a very good catch.

    I'll make a test and send out a PR.

  2. locked as resolved and limited conversation to collaborators on Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScript

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions