felixfbecker / node-sql-template-strings

ES6 tagged template strings for prepared SQL statements 📋
ISC License
610 stars 40 forks source link

error with typescript #23

Closed abenhamdine closed 7 years ago

abenhamdine commented 7 years ago

Hello Felix, and thx for this very useful module.

I'm currently migrating a project on Typescript (version 2.1.4) and I'm running into a type error

import sqlTemplate = require('sql-template-strings');

var foo: number = 1;

const sql = sqlTemplate`  SELECT
                            pay_etablissement_eta.eta_id
                        FROM
                            pay_etablissement_eta
                        WHERE
                            pay_etablissement_eta.pad_id = ${foo}
                        LIMIT 1;`;

produces the following error :

image

Do you understand the rationale of this error ? Any idea to fix it ?

Thx by advance.

FWIW, my ts compile options :

"compilerOptions": {
        "removeComments": true,
        "compileOnSave": true,
        "sourceMap": false,
        "moduleResolution": "node",
        "pretty": true,
        "module": "commonjs",
        "target": "es6",
        "noImplicitAny": false,
        "strictNullChecks": true,
        "watch": true
    },
--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/39949489-error-with-typescript?utm_campaign=plugin&utm_content=tracker%2F23067419&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F23067419&utm_medium=issues&utm_source=github).
felixfbecker commented 7 years ago

In TypeScript, you should use

import SQL from 'sql-template-strings'
abenhamdine commented 7 years ago

Ah thx a lot. It's sometimes difficult for a newcomer to typescript to sort out all the different export/import patterns...

felixfbecker commented 7 years ago

The definition file can tell you: https://github.com/felixfbecker/node-sql-template-strings/blob/master/index.d.ts#L76

abenhamdine commented 7 years ago

ah thx again ! I think I get it now.