Node.js / mssql / typescript
I'm trying to build a set of input parameters dynamically and add them to a prepared statement. With the code below, the error I get is:
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ VarChar: ISqlTypeFactoryWithLength; NVarChar: ISqlTypeFactoryWithLength; Text: ISqlTypeFactoryWithNoParams; ... 29 more ...; Variant: ISqlTypeFactoryWithNoParams; }'.
import { TYPES, PreparedStatement } from 'mssql'
...
const ps = new PreparedStatement(pool);
parameters.forEach((param: IParam) =>{
let t1 = TYPES[param.dataType]; // ** This doesn't work **
ps.input(param.name, t1);
values[param.name] = param.value;
});
...
export interface IParam {
name: string;
dataType: string;
length: number;
value?: string;
}
Oddly (to me anyway) I can use this code without issue.
let t1 = TYPES['VarChar']; // This does work
Any help would be much appreciated.