简体   繁体   中英

Not all braintree HostedFields methods available for typescript?

I'm using Braintree Sandbox in my ReactJs project with typescript.

According to Braintree Docs for focus, a field can be focused using the .focus() method.

hostedFieldsInstance.focus('number', function (focusErr) {
  if (focusErr) {
    console.error(focusErr); 
  }
});

Issue: In my typeScript file, hostedFieldsInstance is not showing the .focus() method as a valid method. Im getting the following error:

Property 'focus' does not exist on type 'HostedFields'.ts(2339)

VS Code is also suggesting only few existing braintree methods but not .focus() :

在此处输入图像描述

The TS definitions from DefinitelyTyped don't include that function, but that doesn't mean that you cannot call it regardless. Your options include:

  • Bypassing the TS compiler check in that case ( (hostedFields as any).focus(...) )
  • Writing your own type definitions for BrainTree, importing the existing ones from DefinitelyTyped and overriding them to add what you need
  • Waiting for the BrainTree TS rewrite (see this comment )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM