I'm trying to integrate a Javascript Library (Microsoft Playfab) into my React Native app as per recommended here. The library comes with typings and has the structure as shown here. I have a file playfabWrapper.ts
with the following.
/// <reference path="../../node_modules/playfab-web-sdk/src/Typings/PlayFab/PlayfabClientApi.d.ts" />
import Playfab from 'playfab-web-sdk/src/PlayFab/PlayFabClientApi.js';
function test(titleId: string, customId: string/*, success: (data: PlayFabClientModels.LoginResult) => void, error: (message: string) => void*/): void {
Playfab.ClientApi.LoginWithCustomID({
TitleId: titleId,
CustomId: customId,
CreateAccount: true,
}, (result: any, problem: any) => {
...
});
}
This gives me the error
Could not find a declaration file for module 'playfab-web-sdk/src/PlayFab/PlayFabClientApi.js'. '/Users/../project/node_modules/playfab-web-sdk/src/PlayFab/PlayFabClientApi.js' implicitly has an 'any' type.
Try `npm install @types/playfab-web-sdk` if it exists or add a new declaration (.d.ts) file containing `declare module 'playfab-web-sdk/src/PlayFab/PlayFabClientApi.js';`
Then I tried copying the typings from Typings/Playfab and pasting them in the same location as PlayFabClientApi.js
. This gives me the following error.
File '/Users/../project/node_modules/playfab-web-sdk/src/PlayFab/PlayFabClientApi.d.ts' is not a module.
Interestingly, if I delete the import line my IDE can detect Playfab
correctly but it is always undefined. Am I missing something? Is this kind of library even possible to import? I notice it doesn't have an index.d.ts
, could that contribute to the issue? Any help would be appreciated. Thanks.