-
-
Notifications
You must be signed in to change notification settings - Fork 677
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
Is mixin two more object types into another object type supported? #532
Comments
I don't understand your question. Can you show what you've tried to do that is not working?
TypeScript doesn't support multiple inheritance, you need to use mixin pattern showed in examples. |
So I am trying to use mixin as defined here:
However the mixed Then I stumbled upon this this thread: Here it has an example of js based mixin Also as mentioned in that thread, there is no port of the same in TS. Lastly there is an example: Note each of the class is decorated with So is there any example that can show how we can mix two classes of |
It's deprecated and superseded by ES6 class mixins, just because the old mixins doesn't work 😄
The answer is really simple - you just can't. You need to duplicate the properties and decorator or switch to ES6 mixins, where you prefer composition of small classes, rather than inheritance of big blocks. |
So once I switch to ES6 mixins in typescript, it does not seem to be supported. I have also checked this PR Here again if you see the example it is adding mixin(s) to single class. However is we just use the same example and imagine that |
Hi guys. I'm using TypeORM and I'm isolationg TypeORM decorators in my entities (User, GroupMember). For TypeGraphQL fields I'm using UserFields GroupMemberFields which are classes using just TypeGraphQL decorators. I prefered to used this approach instead of keeping all decorators in my TypeORM entities. As mentioned by @MichalLytek I didn't know that this feature typescriptlang.org/docs/handbook/mixins.html was deprecated, didn't find this information in this link. I achieved the desired schema generated by doing: class mixed: GroupMemberUser.ts
Group.ts (TypeORM entity)
The schema generated:
Hope this helped. |
Example
I have two object types:
I want to create a new
class C
composed of fields fromA
andB
.Now typescript supports this and also there is a mixin example in type-graphql.
However the example is to mix only one class in some other class.
When I try to compose a new class the way typescript supports, it does not copy the decorators to the new class and the schema generated from that new class does not has the compose fields.
Any other way if this is possible?
The text was updated successfully, but these errors were encountered: