1

I have a nodejs typescript project that requires the use of mysqljs (https://www.npmjs.com/package/mysql), I've imported the DefinitelyTyped package (https://www.npmjs.com/package/@types/mysql) and included them in my tsconfig file

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" ] }

I can correctly use the mysql module functions but I cannot access the types (IConnection, IQuery, etc). I can also see the parameter and return types from intellisense.

Example

import * as mysql from 'mysql'
...
getUser(username: string): User {
        mysql.createConnection({ host: "...", user: "...", password: "..." });
    }

But I'd like to make a method that returns a type defined in the mysql typings (IQuery for example)

Something like

getUser(username:string): IQuery{
}

Being a beginner in typescript coming from a c# background, I don't see what's going on here.

Thanks for the help.

EDIT: I have tried prefixing he type without any success as well as importing through this format import {IConnection} from 'mysql' Thanks again.

2 Answers 2

1

It seems as though ReSharper was my issue, I still haven't found how to omit the errors or fix them though. I reinstalled Visual Studio 2017 and it worked without Resharper, but when I did install it, I started having problems again. Thanks for the help! I'll edit this if I can find a solution.

Sign up to request clarification or add additional context in comments.

Comments

0

You can access it by prefixing the interface with mysql:

getUser(username:string): mysql.IQuery {

}

5 Comments

I tried that but it still doesn't show up or compile, maybe it's my IDE?
Have you actually installed the types? npm install @types/mysql --save-dev
Yes, I can see the types in my IDE, I just can't seem to be able to access them from outside the module. I also tried your command with no success.
I am able to use the interface with your exact same tsconfig. Can you post something reproducible?
It seems as though ReSharper was my issue, still haven't found how to fix it but it's out of subject.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.