noob7
noob7

Reputation: 1147

typescript export object error declaration or statement expected

Can someone please explain why this works in typescript while exporting an object:

export const config={
port:4000
};

This also works:

const config = { port:4000 };
export { config };

But this gives an error

const config={
  port:4000
};
export config;

Error : declaration or statement expected.

Upvotes: 4

Views: 5578

Answers (1)

Arpit Solanki
Arpit Solanki

Reputation: 9931

export expects a type object or curly braces. The second version is a syntax error.

If you want to export just a config objects then do

export const config = { port:4000 };

From the docs:

This can also be written as export {config};

Upvotes: 2

Related Questions