4

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?

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

1 Comment

In case of IFoo & Foo from the example above, what would module augmentation look like? Could you add it to the answer?

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.