Javascript Typescript无法识别未类型化节点模块的构造函数
这是我第一次用TypeScript和JavaScript写东西。我现在面临一个问题,我需要使用一个非常老的脚本。我是这样导入的:Javascript Typescript无法识别未类型化节点模块的构造函数,javascript,typescript,node-modules,Javascript,Typescript,Node Modules,这是我第一次用TypeScript和JavaScript写东西。我现在面临一个问题,我需要使用一个非常老的脚本。我是这样导入的: import * as D2L from 'valence/lib/valence' 当我尝试使用它时: let appContext = new D2L.ApplicationContext('asd', 'asd').createUrlForAuthentication('wlutest.brightspace.com', 443, 'localhost:810
import * as D2L from 'valence/lib/valence'
当我尝试使用它时:
let appContext = new D2L.ApplicationContext('asd', 'asd').createUrlForAuthentication('wlutest.brightspace.com', 443, 'localhost:8100/callback');
弹出此错误:
错误类型错误:_valenceES6_u网页包_导入的_模块_8_uu。ApplicationContext不是构造函数
我已经尝试过为这个模块生成d.T,但是唯一的效果似乎是使我的IDE平静下来,但是错误仍然存在。
我以前没有使用JavaScript的经验,但从valence.js
的第193行开始,我觉得这是一个合适的构造函数:
/**
* Build a new ApplicationContext instance.
*
* An application context stores the state of the application (app ID, and app
* Key) and provides methods for authentication. Given the authentication
* information, it creates a {@link D2L.UserContext} with the appropriate
* arguments.
*
* @param {String} appId Application ID as provided by Desire2Learn's key tool.
* @param {String} appKey Application Key as provided by Desire2Learn's key tool.
*
* @constructor
* @this {D2L.ApplicationContext}
*/
D2L.ApplicationContext =
function (appId, appKey) {
// Previous version took an appUrl as a first argument but threw it
// away. This provides backwards compatibility for that contract.
if (arguments.length === 3) {
appId = arguments[1];
appKey = arguments[2];
}
this.appId = appId;
this.appKey = appKey;
};
我还尝试使用工具将此文件转换为其他js版本,但没有成功。有人能解释一下吗 结果表明我使用的模块已经过时了,在JS文件的末尾甚至没有
module.exports=…
。添加这些之后,我的项目现在可以识别库了。结果表明,我使用的模块已经过时,甚至在JS文件末尾没有module.exports=…
。添加后,我的项目现在可以识别库了。尝试让appContext=D2L.ApplicationContext('asd','asd')
而不使用new
@Dimanoid。当我删除new
时,我得到了错误类型错误:\u valenceES6\u网页包\u导入的模块\u 8\u。ApplicationContext不是一个正常的函数。因为不应该直接调用类原型。但编译已通过,因此它知道ApplicationContext存在。您的TS配置是否启用了allowSyntheticDefaultImports?请尝试let-appContext=D2L.ApplicationContext('asd','asd'))
无new
@Dimanoid当我删除new
时,我得到错误类型错误:\u valenceES6\uu网页包\u导入的模块\u 8\uuuuuu。ApplicationContext不是一个正常且良好的函数。因为不应该直接调用类原型。但是编译已通过,因此它知道ApplicationContext存在。您的TS配置是否启用了allowSyntheticDefaultImports?