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

add a supertype constraint #14728

Closed
zpdDG4gta8XKpMCd opened this issue Mar 19, 2017 · 4 comments
Closed

add a supertype constraint #14728

zpdDG4gta8XKpMCd opened this issue Mar 19, 2017 · 4 comments
Labels
Duplicate An existing issue was already created

Comments

@zpdDG4gta8XKpMCd
Copy link

zpdDG4gta8XKpMCd commented Mar 19, 2017

currently when we see a constraint <A extends B> it means A is a subtype of B, so that

declare var a: A;
declare var b: B;
b = a; // allowed
a = b; // not allowed

consider adding a new constraint of the reversed relation: <A within B> that would mean A is a supertype of B (or in other words B is subtype of A), so that:

declare var a: A;
declare var b: B;
b = a; // not allowed
a = b; // allowed

use case

i have a BigFatClass with 50 methods and a 1 little property, now i want to run some assertions over it, if i declare these assertions like expect<T>() and toEqual<T> of the same T then toEqual asks me for 50 methods that don't matter for the test, and that's the problem

what i need it to declare expect<T>() and toEqual<U within T>() so that i could simply write:

expect(new BigFatClass()).toEqual({ value: true });
@aaronbeall
Copy link

Can't you use Partial<T> for your assertion?

@zpdDG4gta8XKpMCd
Copy link
Author

@aaronbeall yes, it should work for this very use case, thanks for an idea

@RyanCavanaugh
Copy link
Member

Most recent one tracking this is #14520

@zpdDG4gta8XKpMCd
Copy link
Author

thanks

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 20, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 21, 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

3 participants