Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Namespace has no exported member

Tags:

typescript

When I write this in TypeScript, I get an error saying Namespace Bar has no exported member Qux. Why is that and how do I fix it?

class Foo {}

namespace Bar
{
    export const Qux = Foo;
}

let a: Bar.Qux;
like image 359
m93a Avatar asked Mar 21 '18 11:03

m93a


People also ask

What type of member has no exported?

The error "Module has no exported member" occurs when we try to import a member that doesn't exist in the specified module. To solve the error, make sure the module exports the specific member and you haven't mistyped the name or mistaken named for default import.

What is export type in TypeScript?

TypeScript supports export = to model the traditional CommonJS and AMD workflow. The export = syntax specifies a single object that is exported from the module. This can be a class, interface, namespace, function, or enum.

What is export as namespace?

The export as namespace form creates a global variable so it can be used without importing, but you may still import it with the import { name } from "some-library" form of import.

How do I export a function in TypeScript?

Use named exports to export a function in TypeScript, e.g. export function sum() {} . The exported function can be imported by using a named import as import {sum} from './another-file' . You can use as many named exports as necessary in a single file.


1 Answers

You are exporting a constant, not a type. You can do this let a = new Bar.Foo(), and a will be of type Foo.

If you want to export both a type and a constant:

namespace Bar
{
    export const Qux = Foo;
    export type Qux = Foo;
}

Then you can have:

let a: Bar.Qux = new Bar.Qux();

TypeScript will determine, based on context, if you are using the type definition or the constant.

like image 103
Oscar Paz Avatar answered Dec 31 '22 07:12

Oscar Paz