Home > OS >  How to write "module.exports" from javascript to typescript?
How to write "module.exports" from javascript to typescript?

Time:01-18

How do I convert the JavaScript module.exports to typescript

The JavaScript code of the module.exports is :

module.exports = {
    discord: {
        clientID: "",
        clientSecret: "",
        clientToken: "",
    },
    tokens: {
        twitchClientID: "",
        openWeatherMap: "",
    },
};

CodePudding user response:

use export default

const val = {
    discord: {
        clientID: "",
        clientSecret: "",
        clientToken: "",
    },
    tokens: {
        twitchClientID: "",
        openWeatherMap: "",
    },
};
export default val

CodePudding user response:

Try to use the export default keyword:

export default {
    discord: {
        clientID: "",
        clientSecret: "",
        clientToken: "",
    },
    tokens: {
        twitchClientID: "",
        openWeatherMap: "",
    },
}

You can also export single elements (equivalent of module.exports.foo = { ... }):

export const foo = {
    discord: {
        clientID: "",
        clientSecret: "",
        clientToken: "",
    },
    tokens: {
        twitchClientID: "",
        openWeatherMap: "",
    },
}
  •  Tags:  
  • Related