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.

uint32
  • 21
  • 1
  • 5

2 Answers2

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.

uint32
  • 21
  • 1
  • 5
0

You can access it by prefixing the interface with mysql:

getUser(username:string): mysql.IQuery {

}
Saravana
  • 37,852
  • 18
  • 100
  • 108
  • I tried that but it still doesn't show up or compile, maybe it's my IDE? – uint32 Aug 23 '17 at 04:45
  • 2
    Have you actually installed the types? `npm install @types/mysql --save-dev` – Saravana Aug 23 '17 at 05:28
  • 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. – uint32 Aug 23 '17 at 14:27
  • I am able to use the interface with your exact same `tsconfig`. Can you post something reproducible? – Saravana Aug 23 '17 at 14:55
  • It seems as though ReSharper was my issue, still haven't found how to fix it but it's out of subject. – uint32 Aug 24 '17 at 01:55