我有一个需要使用 mysqljs ( https://www.npmjs.com/package/mysql ) 的 nodejs typescript 项目,我已经导入了definitelyTyped 包( https://www.npmjs.com/package/@types /mysql)并将它们包含在我的 tsconfig 文件中
tsconfig.json
{“compilerOptions”:{“noImplicitAny”:假,“模块”:“commonjs”,“noEmitOnError”:真,“removeComments”:假,“sourceMap”:真,“目标”:“es6”},“排除” :[“node_modules”],“typeRoots”:[“node_modules/@types”,“脚本/打字/节点”],“类型”:[“mysql”,“node”]}
我可以正确使用 mysql 模块功能,但无法访问类型(IConnection、IQuery 等)。我还可以从智能感知中看到参数和返回类型。
例子
import * as mysql from 'mysql'
...
getUser(username: string): User {
mysql.createConnection({ host: "...", user: "...", password: "..." });
}
但我想创建一个返回 mysql 类型中定义的类型的方法(例如 IQuery)
就像是
getUser(username:string): IQuery{
}
作为来自 ac# 背景的打字稿初学者,我不明白这里发生了什么。
谢谢您的帮助。
编辑:我尝试在他的类型前加上前缀但没有任何成功,以及通过这种格式导入import {IConnection} from 'mysql'
再次感谢。