Typescript question: interface that extends a generic

11 views
Skip to first unread message

Christophe HOARAU

unread,
Feb 22, 2019, 2:31:13 AM2/22/19
to Angular and AngularJS discussion
Hello,

I know this is not specific to angular, but as angular is one of the most active typescript users I was wondering if someone could help me on this one.

I want to create an interface that extends a generic. Something like this :

export interface A{
    A: string;
}

export interface AB{
    B: string;
}

export interface AC{
    C: string;
}


export interface AX<T extends A> extends T{
    X: string;
}

This way I could use AX in places where I need A and X.
I know this might sound a bit weird, but I really need this.

Thanks.
Best regards.

Lucas Lacroix

unread,
Feb 22, 2019, 7:18:45 AM2/22/19
to ang...@googlegroups.com
Typescript has composition, so this really isn't necessary.

interface A {}

interface X {}

function f(ax: A&X) {}



--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

                
Subscribe to receive emails from MEDITECH or to change email preferences.

Christophe HOARAU

unread,
Feb 22, 2019, 9:47:27 AM2/22/19
to Angular and AngularJS discussion
Thanks I'll try that, I don't know why I didn't thought about it. I already used this syntax.
Reply all
Reply to author
Forward
0 new messages