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 new mapped-type for intersection more than two classes #339

Closed
trycontrolmymind opened this issue Apr 21, 2021 · 7 comments
Closed

Add new mapped-type for intersection more than two classes #339

trycontrolmymind opened this issue Apr 21, 2021 · 7 comments

Comments

@trycontrolmymind
Copy link
Contributor

I'm submitting a...


[ ] Regression 
[ ] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

import { IntersectionType } from '@nestjs/mapped-types';
import { BaseTemplateFiltering } from 'validators/BaseTemplateFiltering';
import { LimitOffsetQuery } from 'validators/LimitOffsetQuery';
import { SortByQuery } from 'validators/SortByQuery';

export class BaseTemplateQueryDto extends IntersectionType(
  BaseTemplateFiltering,
  IntersectionType(LimitOffsetQuery, SortByQuery),
) {}

Wanted behavior

import { IntersectionMultipleType } from '@nestjs/mapped-types';
import { BaseTemplateFiltering } from 'validators/BaseTemplateFiltering';
import { LimitOffsetQuery } from 'validators/LimitOffsetQuery';
import { SortByQuery } from 'validators/SortByQuery';

export class BaseTemplateQueryDto extends IntersectionMultipleType(
  BaseTemplateFiltering,
  LimitOffsetQuery, 
  SortByQuery,
) {}

I don't think is it possible to do things such this...

@jmcdo29
Copy link
Member

jmcdo29 commented Apr 21, 2021

Might be a bit ugly, but as these types are composable you could do something like

const BasetemplateQueryDto extends IntersectionType(
	IntersectionType(
		BaseTemplateFiltering,
		LimitOffsetQuery
	),
	SortByQuery
) {}

Just a thought until there's an official verdict on this. Don't immediately know what would happen to duplicate keys, what kind of precedence would take, so be wary of that.

@kamilmysliwiec
Copy link
Member

Would you like to create a PR for this issue? We can let `IntersectionType accept a spread arg (infinite number of args) and just combine them all.

@trycontrolmymind
Copy link
Contributor Author

Would you like to create a PR for this issue? We can let `IntersectionType accept a spread arg (infinite number of args) and just combine them all.

Okay, i'll try ​this week

@altick
Copy link

altick commented Apr 23, 2021

A bit off-topic question, but why is this function called intersection when it actually gives a union of the given types? Personally I understand the intersection as something that exists in all given places 🤔

@trycontrolmymind
Copy link
Contributor Author

@altick Yep it was a bit stange for me tooo

intersection should be something like this, but now it's work as union
image

@kamilmysliwiec
Copy link
Member

@trycontrolmymind @altick check out this link https://www.reddit.com/r/typescript/comments/9qduq3/why_is_type_intersection_called_like_that_its/ to learn more on why we (and TypeScript itself) use Intersection/Union names here.

Let's track this here #341

@trycontrolmymind
Copy link
Contributor Author

Could someone review PR #341 with new functionality, after that I could edit documentation after review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants