镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Omit breaks in 3.9.2 #38531

Closed
Closed

Description

TypeScript Version:
3.9.2

Search Terms:
3.9.2 Omit

Code

interface A { 
  my: 'aaa';
}

interface B { 
  my: 'bbb';
}

interface C extends Omit<A & B, 'my'> { 
  my: string;
}

Expected behavior:

Can define my with Omited like prev version.

Actual behavior:

Property 'my' of type 'string' is not assignable to string index type 'never'.(2411)

Playground Link:

https://www.typescriptlang.org/play/?ssl=1&ssc=1&pln=12&pc=1#code/JYOwLgpgTgZghgYwgAgILIN7ILAChnIC2AngFzIDkc1FA3HgL556iSyIoBCmO+RZlAEbC6jZrlbR4SZAGFkEAB6QQAEwDOyAPKFgYADzoAZMk4AaSiQoA+HngIly6sFFABzeria4gA

Related Issues:

Activity

  1. kitsonk commented on May 13, 2020

    @kitsonk
    Contributor

    Effectively duplicate of #38241, related to breaking change #37195.

  2. ahejlsberg commented on May 14, 2020

    @ahejlsberg
    Member

    The issue here is that A & B is an empty intersection (i.e. a type for which you couldn't possibly construct a value) that now reduces to never. We previously didn't catch such types.

    You could instead write your code as

    type Base = Omit<A, 'my'> & Omit<B, 'my'>;
    
    interface C extends Base { 
      my: string;
    }

    That is, omit the conflicting discriminants before you intersect the types.

  3. ahejlsberg commented on May 14, 2020

    @ahejlsberg
    Member

    Yes, but any type that includes a property of type never is a type with no possible values, so we're not talking about something that couldn't exist in the real world. Ideally we'd reduce all such types to never (that is, instead of { my: never } we'd simply have never) but it is costly to check for and tricky to do in a lazily evaluated type system.

  4. typescript-bot commented on May 16, 2020

    @typescript-bot
    Contributor

    This issue has been marked 'Working as Intended' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

  5. 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

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