Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how do you run in a typescript app? #12

Closed
imranity opened this issue Dec 27, 2019 · 2 comments
Closed

how do you run in a typescript app? #12

imranity opened this issue Dec 27, 2019 · 2 comments

Comments

@imranity
Copy link

im new to react but my react app is created in typescript. when i follow your tutorial , i get

Failed to compile.

......SomeFile.tsx
Type error: Property '_env_' does not exist on type 'Window'.  TS2339

    12 |         }
    13 | 
  > 14 |         return window._env_.REACT_APP_BACKEND_API_BASE_URL + '/rest';
       |                       ^
    15 |     }
    16 | 
    17 |     protected withResponseCheck(promise: Promise<any>, returnJson: boolean): Promise<any> {

i confirmed my env-config.js generated inside public has window.__env__ being set

window._env_ = {
  REACT_APP_BACKEND_API_BASE_URL: "http://localhost:5000"
}
@route2Dev
Copy link

in TypeScript 3.4.5 and above...

Create a file called window.d.ts under src with the following code

interface Window {
    _env_ : any
}

@kunokdev
Copy link
Owner

kunokdev commented Aug 24, 2020

⬆️ Please use solution above!

Already asked here: #3

Also instead of using any I highly recommend to create configuration interface.

As TypeScript is now a standard way to write JS, I will add link to this in README.md and blog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants