Skip to content

Exact type intersections are unsound #7416

@jfirebaugh

Description

@jfirebaugh

Flow v0.91.0 accepts the following (try):

function fn<T, U>(x: $ReadOnly<T & U>): T {
  return x;
}

const exact: {| a: any |} = fn<{| a: any |}, { b: any }>({ a: 1, b: 1 });

This potential for unsoundness with intersections of exact types was noted in this comment in the discussion about adding exact types to TypeScript.

The comment notes "it's really not OK to error on instantiation" -- is this a principle Flow adheres to as well? If so, it seems there is indeed no way to make this sound. But if not, this should be an error -- something like "Cannot call fn with object literal bound to x because object literal [1] is incompatible with empty [2]."

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions