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

Possible to get a "difference" type i.e. type A - type B ? #14626

Closed
AJamesPhillips opened this issue Mar 13, 2017 · 1 comment
Closed

Possible to get a "difference" type i.e. type A - type B ? #14626

AJamesPhillips opened this issue Mar 13, 2017 · 1 comment
Labels
Duplicate An existing issue was already created

Comments

@AJamesPhillips
Copy link

AJamesPhillips commented Mar 13, 2017

Given:

interface Base {
  field1: string;
}
interface ConcretePartial {
  field2: string;
}
interface Concrete extends Base, ConcretePartial {
}

var some_base_fields: Base = {field1: ''};
var extra_fields_for_concrete: ConcretePartial = {field2: ''};
var new_object: Concrete = _.assign<{}, Base, ConcretePartial>({}, some_base_fields, extra_fields_for_concrete)

I'm wondering if it is possible to get a type with the structure of Concrete ∖ Base (i.e. {field2: string }) so that instead you could use:

var new_object: Concrete = _.assign<{}, Base, Concrete ∖ Base>({}, some_base_fields, extra_fields_for_concrete)

I've read https://www.typescriptlang.org/docs/handbook/advanced-types.html and checked the issues and it doesn't seem possible. I wanted to confirm that that's the case and if there were any plans for this "shorthand" type difference notation? Also if there's a better pattern to use when dealing with extended interfaces, for example the OOP class approach would simplify this but I was curious if it's possible to do easily with interfaces?

@kitsonk
Copy link
Contributor

kitsonk commented Mar 13, 2017

Dupe of #4183

@mhegazy mhegazy added the Duplicate An existing issue was already created label Mar 13, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants