JavascriptLoser
JavascriptLoser

Reputation: 1962

Typescript can't import function that is exported from a module

This should be such a simple problem but for some reason I can't figure it out.

I have two files:

//Exporter.ts
export module Exporter {
     function foo = { return 1; }
}

//Importer.ts
import { foo } from './Exporter';

This gives me a typescript error Exporter has no exported member foo

But it's clearly being exported. What is the problem here?

Upvotes: 1

Views: 567

Answers (1)

Andrew Shepherd
Andrew Shepherd

Reputation: 45252

You don't need the export module... wrapping code inside Exporter.ts.

The entirety of Exporter.ts became a module as soon as you added the export keyword to it.

Simply write:

// Exporter.ts
export function foo() { return 1; }


// Importer.ts
import { foo } from './Exporter';

Upvotes: 1

Related Questions