node-odbc
node-odbc copied to clipboard
[TypeScript] Change API types from class to interface
These types don't actually exist at runtime, or at least they are not exported.
For example, this code will compile but fail at runtime with TypeError: Right-hand side of 'instanceof' is not an object:
const odbc = require('odbc');
try {
// run some queries
} catch (e) {
if (e instanceof odbc.NodeOdbcError) {
// handle error
}
}
@worksofliam can you look at this? I'm not familiar enough with TypeScript to review this.
@kadler I am not able to leave reviews, but I'd say this is partially correct and therefore requires more changes (or maybe less changes). It makes sense to convert the class signatures to interface when they have no properties which are instances methods. I wouldn't be converting Statement and Pool to use interface.
@dwickern For your comparison there, you might be better off with if ('odbcErrors' in e) {
Sorry, I'm not sure I understand your suggestion about instance methods.
This PR fixes the types to match the runtime behavior. Unlike interface which is a compile-time construct, a class has a runtime representation. This code should not compile because none of these things have a runtime representation:
import odbc from 'odbc'
odbc.ColumnDefinition // undefined
odbc.Result // undefined
odbc.OdbcError // undefined
odbc.NodeOdbcError // undefined
odbc.Statement // undefined
odbc.Connection // undefined
odbc.Pool // undefined
odbc.Cursor // undefined
@dwickern Hey again. Had a look properly this and yes, it makes sense. My bad, I forgot node-odbc is not TS!