DefinitelyTyped @types and lean imports

151 Views Asked by At

If my project includes @types/braintree-web and I

import braintree from 'braintree-web'

const client = braintree.client

then client is properly typed as braintree.Client.

However, I want to use lean imports like:

import braintreeClient from 'braintree-web/client/index.js'

and I want braintreeClient to also be typed as braintree.Client. Instead, I get TypeScript warnings:

Could not find a declaration file for 'braintree-web/client/index.js'

Was thinking I would add this to my global.d.ts...

/// <reference types="braintree-web" />

declare module 'braintree-web/client/index.js' {
  
}

Is there a way where I can reuse the typings that were already defined for 'braintree' rather than recreate them for each lean import?

1

There are 1 best solutions below

1
Derek Lawrence On
import { braintreeClient } from 'braintree-web'

Or this may work as well

import * as braintreeClient = from 'braintree-web/client'