Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 483
noob7 Avatar asked Sep 17 '25 21:09

noob7


1 Answers

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};

like image 105
Arpit Solanki Avatar answered Sep 19 '25 12:09

Arpit Solanki