score:11
In TypeScript, you need to set the return value so if this string did so
const configValue : string = process.env.REACT_APP_SOME_CONFIGURATION
OR
const configValue: string = (process.env.REACT_APP_SOME_CONFIGURATION as string);
score:1
You can add this to your react-app-env.d.ts
file
declare namespace NodeJS {
interface ProcessEnv {
//types of envs
NODE_ENV: 'development' | 'production' | 'test';
PUBLIC_URL: string;
}
}
score:2
You could change this to a string or Undefined for a failing scenario like so
const configValue : string | undefined = process.env.REACT_APP_SOME_CONFIGURATION
score:3
Update on March 2021: With React 17 and typescript, you don't need to set the return the 'configValue' value, just use the env variable like you did before. My .env file like this
REACT_APP_STRING=some_string_dont_have_quotation_mark
Source: stackoverflow.com
Related Query
- how to use .env file in a react js with typescript project?
- How can I use the css file from react-table in my react project along with css modules?
- How to use refs in React with Typescript
- How to use React with Typescript and SASS
- How to import scss file as variable in react with typescript
- How to use forwardRef with FunctionComponent in React Native using TypeScript
- How to use Material UI custom theme in React with Typescript
- How to use jest.spyOn with React function component using Typescript
- How do you correctly use React.lazy() in Typescript to import a react component with a generic type parameter?
- How to use Antdesign with tailwindcss together in a React Project
- React how to use icon inside Textfield Material-UI with TypeScript
- How to use Refs with Material-ui 4, React 16.8, TypeScript 3.5
- How to import .json file with typescript React App
- How to use Material UI custom variants in React with Typescript
- How to use emotion/styled with React and Typescript
- How to use radium in React typescript (Error: has no properties in common with type 'CSSProperties'. TS2559)?
- How to use React Hook Form with Typescript (Input Component)
- How can I access a local JSON file with Redux to use throughout my React app?
- How to use react-datetime with react + typescript (inside tsx)
- How to use React refs with new Typescript strictPropertyInitialization option?
- How to use useState hook in React with typescript correctly?
- How to use PropTypes with Typescript in React
- How to use mixins with Typescript and React JSX (TSX)
- How to use Typescript with React Router and match
- How using types.d.ts file in React & TypeScript project
- How to properly use TypeScript types with a Styled Component canvas on React
- How to centralize interface initialization in React project with Typescript
- How to use TypeScript with React / Redux mergeProps
- How to use delete request with axios in react project and Firebase?
- How to use Facebook Javascript SDK to login and force re-authentication with React Web and Typescript inside of a component
More Query from same tag
- Conditional output HTML in jsx
- Semantic UI React change style placeholder text CSS
- How do I use Redux Toolkit with multiple React App instances?
- ReactJS assign a function to a variable using hook?
- TypeScript is using different versions of @types for react
- Unable to type in input field React
- OnClick related function from react component doesn't work
- Material ui DatePicker enable only year
- How Do you reset the CSS in React if you're doing styled components?
- react-scroll having problems with ES6
- when image tag role be set button jsx-a11y show warning
- React Transition CSS animation flickering
- Google chrome logs indicating xml.js:30 instead of actual line
- How to avoid reactjs to be included twice in a rails and reactjs environment?
- React Context API doesn't work for single application dialog
- Module not found: Error: Can't resolve 'dns' when using MongoDB
- Cannot get attribute size from File object in React
- useEffect keep getting executed every time even dependency not changed
- React compose prevent div wrap
- Overriding MUI Stepper styles in React 2022
- Mutually updating input fields using React
- prevent onDocumentMouseDown when clicking a button?
- Modify object values by finding keys dynamically TypeScript
- how to force to function execute only when after another async function complete
- Context API problem - object is undefined
- .map function in react not display any data
- State undefined in redux
- How to get failed or popup close event of razorpay
- component not rendering react-router v4
- Accessing Redux from normal JS file which is not component