Navigate back to the homepage

how to export constants in typescript?

Infinitbility
TypeScript
July 24th, 2022 · 1 min read
how to export constants in typescript?

Export constants in typescript

To export constants in typescript, use the export keyword it will export your constants, variables, or functions.

To use export constants, variables, or functions in typescript, use the import keyword. using the import keyword you can easily use exported module.

Today, I’m going to show you How do i export constants in typescript, as mentioned above, I’m going to use the use export statement to export constants and use them in another file.

Let’s start today’s tutorial how do you export constants in typescript?

In this example, we will do

  1. export sample constants variable in one file
  2. import exported constants in another file
  3. use the imported variable in a file

constants.ts

1// 👇️ named export
2export const APP_NAME: string = 'Infinitbility';
3
4// 👇️ named export
5export const APP_URL: string = 'https://infinitbility.com';

In the above typescript example, we exported some string constants variables now we are going to use them in another file.

index.ts

1// 👇️ named import
2import { APP_NAME, APP_URL } from './constants';
3
4console.log(APP_NAME); // 👉️ "Infinitbility"
5console.log(APP_URL); // 👉️ "https://infinitbility.com"

TIP: Same as import you can export all constants at one line. eg: export { APP_NAME, APP_URL }

I hope it helps you, All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

how to extract numbers from the string in typescript?

how to extract numbers from the string in typescript?

TypeScript, export constants example with the step-by-step guide.

July 24th, 2022 · 1 min read
how to remove space between strings in javascript?

how to remove space between strings in javascript?

An example of removing space between strings in javascript with step by step guide.

July 23rd, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]