I'm new to ES6 and TypeScript. We have refactored some of our code to ES6 but we a trying out if it wouldn't be better to switch to TypeScript instead for writing more maintainable code easier.
If have the following, simplified ES6 module config.js
export default {
logger: require('winston'),
somethingelse: 'text'
}
I import this module everywhere throughout my project, such as in app.js
:
import * as config from '../../../../config'
const logger = config.logger
...
As far as I understand, typing is optional in TypeScript and ES6 code should just run fine if I just rename the files from .js
to .ts
. Please correct me if that was a wrong assumption I had. However, I get this error when I compile:
/project/app.ts(7,23): Property 'logger' does not exist on type 'typeof \"/project/config\"'.
So that means, I have to declare a type? So then I went ahead and declared an interface for the exported object.
config.js
:
interface IConfig {
logger: any;
somethingelse: string;
}
const defaultConfig: IConfig = {
logger: winston,
text: 'text'
}
export default defaultConfig
But I'm still getting the above compilation error.