TypeScript icon indicating copy to clipboard operation
TypeScript copied to clipboard

TS4023: Exported variable 'X' has or is using name 'Y' from external module 'a/file/path' but cannot be named

Open janakerman opened this issue 11 years ago • 24 comments

I'm attempting to create a set of external TypeScript modules as follows:

// ClassA.ts
export default class ClassA {
  public method() { return true; } 
}

// ModuleB.ts
import ClassA from './ClassA';
var moduleB = {
  ClassA: ClassA
};
export default moduleB;

// ModuleA.ts
import moduleB from './ModuleB';
var moduleA = {
  moduleB: moduleB
}
export default moduleA;

The idea is that this will be compiled down and supplied as a library. The plan is that the consumer of the library will instantiate an instance of ClassA as follows:

import moduleA from './ModuleA';
var anInstance = moduleA.moduleB.ClassA();

This looks as though it is compiling down to the expected JS, but I'm getting an error compiler error which I'm struggling to find further information about.

Using tsc v1.6.2
.../src/ModuleA.ts(3,5): error TS4023: Exported variable 'moduleA' has or is using name 'ClassA' from external module ".../src/ClassA" but cannot be named.

Can anyone here shed any light on this issue? Does what I'm trying to do make sense?

janakerman avatar Nov 18 '15 13:11 janakerman

Did anyone figured out how to deal with noUnusedLocals ?

yordis avatar Jan 22 '18 23:01 yordis

@yordis // @ts-ignore

pelotom avatar Jan 22 '18 23:01 pelotom

@pelotom yeah this is completely my fault,

I was thinking on one thing and I wrote something else.

Did Typescript fixed the issue between noUnusedLocals and the declarations?

yordis avatar Jan 22 '18 23:01 yordis

My current workaround, which feels like a total pain to me,

import {SomeInterface} from "./SomeFile";

const _dummySomeInterface : undefined|SomeInterface = undefined;
_dummySomeInterface;

//Code that implicitly uses SomeInterface

Avoids noUnusedLocals, allows type inference for generic interfaces, too, where possible.

AnyhowStep avatar Feb 08 '18 21:02 AnyhowStep