gpt4 book ai didi

node.js - 在 typescript 中使用 mysql 类型

转载 作者:太空宇宙 更新时间:2023-11-04 00:18:12 25 4
gpt4 key购买 nike

我有一个需要使用 mysqljs ( https://www.npmjs.com/package/mysql ) 的 Nodejs TypeScript 项目,我已导入 DefinelyTyped 包 ( https://www.npmjs.com/package/@types/mysql ) 并将它们包含在我的 tsconfig 文件中

tsconfig.json

{ "compilerOptions": { "noImplicitAny": false, "module": "commonjs", "noEmitOnError": true, "removeComments": false, "sourceMap": true, "target": "es6" }, "exclude": [ "node_modules" ], "typeRoots": [ "node_modules/@types", "Scripts/typings/node" ], "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{
}

作为来自 C# 背景的 typescript 初学者,我不明白这里发生了什么。

感谢您的帮助。

编辑:我尝试为他的类型添加前缀,但没有成功,也尝试通过此格式导入 import {IConnection} from 'mysql'再次感谢。

最佳答案

似乎 ReSharper 是我的问题,但我仍然没有找到如何忽略错误或修复它们。我重新安装了 Visual Studio 2017,它在没有 Resharper 的情况下也能工作,但是当我安装它时,我又开始遇到问题。谢谢您的帮助!如果我能找到解决方案,我会编辑它。

关于node.js - 在 typescript 中使用 mysql 类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45829939/

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