Zen-Ventzi-Marinov
Zen-Ventzi-Marinov

Reputation: 4236

Typescript import interface with same name as class

Below works:

interface Foo {
  num: number;
}

class Foo {
}

Below doesn't work, error

Import declaration conflicts with local declaration of 'Foo'

import { Foo } from "./someModule";
class Foo {
}

Is this intended behaviour? If I am able to create an interface and class with the same name in one module, why not be able to import?

Upvotes: 4

Views: 3379

Answers (1)

Titian Cernicova-Dragomir
Titian Cernicova-Dragomir

Reputation: 249756

The behavior is different in the two cases. In the first case you don't end up with an interface and a class, you end up with a single class that is a merger of the two. The behavior is described here. This behavior can't happen across modules however.

If you want to augment an existing module the behavior you want is called module augmentation and is also described here.

Upvotes: 4

Related Questions