Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 518
ZenVentzi Avatar asked Oct 28 '25 18:10

ZenVentzi


1 Answers

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.

like image 135
Titian Cernicova-Dragomir Avatar answered Oct 30 '25 14:10

Titian Cernicova-Dragomir