Sorry for the novice question, but I'm trying to organize my code by moving all constants into a separate file and importing them. However, I can't seem to get it to work despite trying different methods. Most resources I've found online focus on importing classes and functions rather than constants.
In a file called constants.tsx
, I have declared various constants:
export const default_bg = "#2456a5"
export const default_light_font_color = "white"
export const default_lg_font_size = 11
export const default_md_font_size = 10
export const default_sm_font_size = 9
export const default_dark_font_color = "#000028"
export const default_font = "arial"
In my main file with the functionality, App.tsx
:
import * as React from 'react';
import { Header } from './Header';
import { Body } from './Body';
import * as defaults from 'constants'
...
However, when I try to access these constants using defaults.default_bg
, I encounter this error message:
TS2339: Property 'default_bg' does not exist on type 'typeof import("constants")'.
Additionally, when I log defaults
in the console, I see:
https://i.sstatic.net/CP0u5.png
This may be a simple issue, but as someone new to TypeScript and JavaScript, I am struggling to resolve it.