Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从Typescript中的模块导入的函数为';在编译的JS中,t是否被识别为函数?_Javascript_Typescript - Fatal编程技术网

Javascript 从Typescript中的模块导入的函数为';在编译的JS中,t是否被识别为函数?

Javascript 从Typescript中的模块导入的函数为';在编译的JS中,t是否被识别为函数?,javascript,typescript,Javascript,Typescript,我有一个Typescript项目,它从module.js模块调用函数。这是我的初始代码: //app.ts import { MobileServiceUser, setCache, getCache } from "nativescript-azure-mobile-apps/user"; export function onLoginTap(args) { console.log("tap"); ai.busy = true; var cache = getCache

我有一个Typescript项目,它从
module.js
模块调用函数。这是我的初始代码:

//app.ts
import { MobileServiceUser, setCache, getCache } from "nativescript-azure-mobile-apps/user";
export function onLoginTap(args) {
    console.log("tap");
    ai.busy = true;
    var cache = getCache();
}
如果我使用VSCode“转到定义”功能,则
getCache()
转到顶部的import语句,如果我再次执行此操作,则转到:

//module.ts
declare module "nativescript-azure-mobile-apps/user" {

    export class MobileServiceUser {
        mAuthenticationToken: string;
        mUserId: string;

        constructor(o: { userId: string; });
    }

    export function setCache(user: MobileServiceUser): void;
    export function getCache(): MobileServiceUser;
}
当我执行代码时,
var cache=user_1.getCache()行被执行,我的应用程序崩溃,抛出错误:

TypeError:user_1.getCache不是函数 文件:“/data/data/inc.tangra.azuremobileservicessample/files/app/main-page.js,第94行,第23列

app.ts看起来像是编译成js的:

var user_1 = require("nativescript-azure-mobile-apps/user");
function onLoginTap(args) {
    console.log("tap");
    ai.busy = true;
    var cache = user_1.getCache();
}
为什么代码不能识别导入的函数


更新:这显示了项目结构(代码的第一页在sample/main-page.ts

中,您实际的“nativescript azuer mobile apps/user.js或.ts文件”在哪里?@Nathanel,它在node_modules文件夹中。我正在成功地使用从该模块导出的其他类在您的
模块.ts
中,我不确定typescript(从未使用过它),但我知道,如果在对象中放一个分号,JS就会断然拒绝,就像在
构造函数中一样(o:{userId:string;})
尝试删除
字符串后的分号,看看是否有帮助,或者错误是否发生了变化。@Jhecht我恐怕还是会得到相同的结果…为什么
在文件
.ts
中声明模块?