E
E
eQ12018-10-13 10:18:06
typescript
eQ1, 2018-10-13 10:18:06

Config.ts which contains local constants. How to implement?

In simple es6, you can easily implement a configuration file for the contents that are used in the project.

module.exports = {
  THIS_IS_FOO: 'boo',
}

And then without problems to use them in the project.
const { THIS_IS_FOO } = require('./config');
console.log(THIS_IS_FOO); // 'boo'

How can this be done in Typescript?
Tried
export const config = {
  THIS_IS_FOO: 'boo',
}

However, when I try to import I get an error I would not like to use constructs like
import { THIS_IS_FOO } from './config';
[ts] Module has no exported member 'THIS_IS_FOO'
import * as config
import { config } from

and the like.
How to implement this correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel Shvedov, 2018-10-13
@mmmaaak

I usually declare constants one by one, something like this:
export const CONSTANT_1 = '1';
export const CONSTANT_2 = '2';

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question