2
votes

In the DefinitelyTyped repo, why do some libraries' type definition files have exports while others don't? For example, the type definition file for the Facebook SDK lacks exports, but the type definition file for the Amazon Alexa SDK has exports.

I'm asking because the Facebook SDK is the first library I've encountered that lacked exports. I discovered this when I tried to import {AuthResponse} from 'facebook-js-sdk' and the compiler complained that .../node_modules/@types/facebook-js-sdk/index.d.ts' is not a module.

Is there some benefit to omitting exports from type definitions, thereby requiring that the entire SDK is imported (e.g. import 'facebook-js-sdk') instead of being able to import just a few types? Or is @types/facebook-js-sdk simply not written using the latest TypeScript best practices?

Also, does the "import everything" export-less style of type definitions have any downsides or problems associated with it that I should watch out for in my code that's importing it?

Finally, let's say someone accepted a PR to add exports to the Facebook SDK's typings. Would that be a breaking change for existing clients of that type definition? (If so that explains why this hasn't been fixed!)

2

2 Answers

2
votes

I think author talking about @types/facebook-js-sdk npm module which provides types for facebook JS SDK.

And it should be imported with

import 'facebook-js-sdk';

Than you'll be able to use FB.init(params) and params will be required to have type InitParams. So typechecking will work.

-1
votes

Let's have a look how the Facebook SDK is supposed to be used:

The Facebook SDK for JavaScript doesn't have any standalone files that need to be downloaded or installed, instead you simply need to include a short piece of regular JavaScript in your HTML that will asynchronously load the SDK into your pages. The async load means that it does not block loading other elements of your page.

After that, you can use SDK by referring to a single global variable, FB, defined by that piece of javacsript code.

Note that nowhere in the process you had to import anything, Facebook SDK does not use modules.

That's the reason why type declarations for Facebook SDK do not have any exports - that's just not the way the underlying javascript code is supposed to work.