2

I am using global script declaration inside index.html

<!DOCTYPE html>
<html>
    <head>
    <script src='https://js.espago.com/espago-1.1.js' type='text/javascript'></script>
    ...
    </head>
<body>
    ...
</body>

Now I want to use it inside the component.

import * as React from "react";
import * as $ from "jquery";

//how to import Espago?

export default class EspagoPayment extends React.Component<any, any> {
    componentDidMount() {
        $("#espago_form").submit(function(event){
             var espago = new Espago({public_key: 'xxx', custom: true, live: false, api_version: '3'});
             espago.create_token({
                    ...
             });
        });
    }

    render() {
        return (
                ...
        );
    }
}

Webpack gives an error on build.

error TS2304: Cannot find name 'Espago'

How to get Espago visible inside the component?

Maybe there is other way to link to online js resource?

2
  • 1
    @YoannM nope error TS2339: Property 'Espago' does not exist on type 'Window'. Commented Dec 9, 2015 at 22:30
  • Ok... I will remove my comment to avoid any confusion. Commented Dec 10, 2015 at 14:04

1 Answer 1

1

You have to tell TypeScript that it's defined somewhere else.

declare var Espago: any;

See https://stackoverflow.com/a/13252853/227299

Sign up to request clarification or add additional context in comments.

1 Comment

Perfect! Thanks for reference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.