gpt4 book ai didi

javascript - TypeScript:如何从 TypeScript 类调用自定义 utli JS 函数

转载 作者:行者123 更新时间:2023-11-30 17:17:33 26 4
gpt4 key购买 nike

例子:JS 实用程序的功能如下:

BDA.Utils.formatString = function (string) {
(....)
return someFormattedStr;
}

现在我想从我的 TS 类中调用它,如下所示:

export class Building {
image: string;

get getFormatted(): string {
return BDA.Utils.formatString (this.image);
}
}

我在类型脚本中收到一条警告/错误,说它基本​​上可以识别 BDA.Utils

有没有办法让 TS 忽略这个?或将其定义为接口(interface)或其他东西以使其假设存在这样的东西?我的主要问题是嵌套模块/类 BDA->Utils

最佳答案

将此添加到您的代码中:

declare module BDA.Utils {
function formatString(s: string): string;
}

关于javascript - TypeScript:如何从 TypeScript 类调用自定义 utli JS 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25813850/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com