带有类型的Javascript库不是模块(React Native) [英] Javascript Library with typings is Not a Module (React Native)

查看:65
本文介绍了带有类型的Javascript库不是模块(React Native)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图按照推荐的此处所示的结构.我有一个带有以下内容的文件 playfabWrapper.ts .

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) => {
        ...
    });
}

这给了我错误

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';`

然后,我尝试从Typings/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.

有趣的是,如果我删除导入行,我的IDE可以正确检测到 Playfab ,但它始终是未定义的.我想念什么吗?是否可以导入这种库?我注意到它没有 index.d.ts ,这可能是造成此问题的原因吗?任何帮助,将不胜感激.谢谢.

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.

推荐答案

是的,如果没有任何类型信息( index.d.ts 文件),则无法导入这样.您可以尝试 var PlayFab = require("...")(但这取决于您的上下文).

Yes, if it doesn't have any type info (the index.d.ts file), you can't import it that way. You can tryvar PlayFab = require("...") (but that depends on your context).

这篇关于带有类型的Javascript库不是模块(React Native)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆