I
I
Innokenty Ivanov2017-08-01 15:38:08
typescript
Innokenty Ivanov, 2017-08-01 15:38:08

Typescript: Do I need to import all types associated with an imported interface?

export interface IFoo {
    bar: TBar[]
}
type TBar = {
    a: string;
    b: number;
}

If I import an interface IFoo, do I need to import also TBar?
I'm using VS Code, which doesn't give hints for fields in TBar, until you import TBar.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stanislav Makarov, 2017-08-01
@Kenya-West

If you yourself use an identifier of the TBar type, then you need to import it, do not use it, i.e. for example write like this:

const foo: IFoo = {
    bar: [
        {a: "white", b: 10},
        {a: "black", b: 20}
   ]
}

that is not necessary.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question