codingrohtak
codingrohtak

Reputation: 160

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():

enter image description here

Upvotes: 3

Views: 311

Answers (1)

michele b
michele b

Reputation: 1865

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)

Upvotes: 3

Related Questions