5

In typescript, is it possible to do something of the sort:

module module1 {
    export interface Foo {
        data1: string;
    }
    export interface Bar {
        data2: string;
    }
    export function foobar(data: Foo & Bar) {
        //do stuff
        data.data1; data.data2;
    }
}

Namely, force foobar's data parameter to implement both Foo and Bar? And if so, what is the correct syntax?

Thanks.

1 Answer 1

7

You'd have to make a new named interface:

module module1 {
    export interface Foo {
        data1: string;
    }
    export interface Bar {
        data2: string;
    }
    export interface FooAndBar extends Foo, Bar { }
    export function foobar(data: FooAndBar) {
        //do stuff
        data.data1; data.data2;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.