Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit breaks in 3.9.2 #38531

Closed
zombieJ opened this issue May 13, 2020 · 5 comments
Closed

Omit breaks in 3.9.2 #38531

zombieJ opened this issue May 13, 2020 · 5 comments
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug

Comments

@zombieJ
Copy link

zombieJ commented May 13, 2020

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:

@kitsonk
Copy link
Contributor

kitsonk commented May 13, 2020

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

@ahejlsberg
Copy link
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.

@ahejlsberg ahejlsberg added the Working as Intended The behavior described is the intended behavior; this is not a bug label May 14, 2020
@zombieJ
Copy link
Author

zombieJ commented May 14, 2020

@ahejlsberg
Copy link
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.

@typescript-bot
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Working as Intended The behavior described is the intended behavior; this is not a bug
Projects
None yet
Development

No branches or pull requests

4 participants