简体   繁体   中英

Typescript complaining about namespace

I am using node v6.8.0, TypeScript v2.0.3, gulp v3.9.1, and gulp-typescript v3.0.2. When I build with gulp I get an error.

Here is my code

/// <reference path="../_all.d.ts" />
'use strict';

import * as Pool from '~mysql/lib/Pool';
import * as mysql from 'mysql';
import * as conf from '../config/config';

class DbConnection {
    public pool: Pool;

    public static bootstrap(): DbConnection {
        return new DbConnection();
    }

    constructor() {
        const setting: conf.Setting = (new conf.Config()).config();
        this.pool = mysql.createPool({
            connectionLimit: 10,
            host: setting.infiniDbHost,
            user: setting.infiniDbUser,
            password: setting.infiniDbPassword,
            debug: false
       });
   }
}

const dbConnection: DbConnection = DbConnection.bootstrap();
export default dbConnection.pool;

Here is the error that I get:

[11:21:07] Using gulpfile ~/Repos/git/WdAnalytics/gulpfile.js
[11:21:07] Starting 'clean'...
[11:21:07] Finished 'clean' after 21 ms
[11:21:07] Starting 'default'...
src/data/infiniDbConnection.ts(28,16): error TS2503: Cannot find namespace 'dbConnection'.
[11:21:08] TypeScript: 1 semantic error
[11:21:08] TypeScript: 2 emit errors
[11:21:08] TypeScript: emit failed
[11:21:08] Finished 'default' after 1.38 s

Here is my gulpfile.js

var gulp = require('gulp');
var ts = require('gulp-typescript');
var clean = require('gulp-clean');

var src = ['src/**/*.ts', '!src/_all.d.ts'];

gulp.task('default', ['clean'], function() {
    return gulp.src(src)
       .pipe(ts({
           noImplicitAny: true,
           noEmitOnError: true
       }))
       .pipe(gulp.dest('dist/.'))
    ;
});

gulp.task('clean', function() {
    return gulp.src('dist/.', {read: false})
        .pipe(clean())
    ;
});

I can't figure out why it thinks dbConnection is a namespace when it is clearly an object.

我将noEmitOnError: true更改为noEmitOnError: false ,它仍然告诉我存在语义错误,但它可以正常运行。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM