Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs Braintree Web应用程序分析构造函数未定义_Reactjs_Typescript_Braintree_Applepay_Applepayjs - Fatal编程技术网

Reactjs Braintree Web应用程序分析构造函数未定义

Reactjs Braintree Web应用程序分析构造函数未定义,reactjs,typescript,braintree,applepay,applepayjs,Reactjs,Typescript,Braintree,Applepay,Applepayjs,我正在尝试使用Typescript在react项目中实现Apple Pay on checkout。我已经安装了braintree web软件包,并按照braintree网站上的说明初始化了我的ApplePaySession。虽然typescript允许我编译项目,但在浏览器中我调用了newapplepaysession(3,paymentRequest)未定义。我绞尽脑汁,但我不明白出了什么问题。下面是一段关于如何初始化ApplePay的代码片段 import { applePay, Appl

我正在尝试使用Typescript在react项目中实现Apple Pay on checkout。我已经安装了braintree web软件包,并按照braintree网站上的说明初始化了我的
ApplePaySession
。虽然typescript允许我编译项目,但在浏览器中我调用了
newapplepaysession(3,paymentRequest)未定义。我绞尽脑汁,但我不明白出了什么问题。下面是一段关于如何初始化ApplePay的代码片段

import { applePay, ApplePayStatusCodes, ApplePaySession } from 'braintree-web';

...

beginApplePay() {
    if (!this.btApplePayInstance) {
      //throw an erro
    }

    const paymentRequest = this.createPaymentRequest();
    const session = this.createSession(paymentRequest);

    session && session.begin();
  }

  createSession(
    paymentRequest: braintree.ApplePayPaymentRequest
  ): braintree.ApplePaySession | null {
    let session: braintree.ApplePaySession;
    console.log('creating session');
    console.log('Sample payment request: ', paymentRequest);
    console.log(
      'Supports API v3: ' + window.ApplePaySession.supportsVersion(3)
    );


    try {
      debugger;
      session = new ApplePaySession(3, paymentRequest); //this is where it fails
      console.log(session);
    } catch (err) {
      console.log(err);
      //throw an error
      return null;
    }
我的浏览器是这样说的:
TypeError:undefined不是构造函数(正在评估“new braintree\u web\u WEBPACK\u IMPORTED\u MODULE\u 1\u[“AppleParysession”](3,paymentRequest)

如果您能深入了解问题所在,我们将不胜感激

我发现

<script src="https://js.braintreegateway.com/web/3.55.0/js/apple-pay.min.js"></script>

在顶层,Js文件对我有效,然后在使用会话时只使用@ts ignore


丑陋的工作我知道。。。如果您找到了更好的解决方案,请与我们分享。

更新:我发现这是一个特定于typescript的问题。在braintree web的类型定义中,它们定义了一种
ApplePaySession
类型。构建项目时,浏览器认为
ApplePaySession
是对braintree web中某个类的引用,而实际上它是对safari浏览器固有的
ApplePaySession
的引用

我找到的解决方案是使用ApplePayWebJS的类型并引用那里提供的
ApplePaySession
。然而,当试图使两个包的类型很好地配合使用时,这确实会产生一些问题