简体   繁体   English

打字稿抱怨名称空间

[英]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. 我正在使用节点v6.8.0,TypeScript v2.0.3,gulp v3.9.1和gulp-typescript v3.0.2。 When I build with gulp I get an error. 当我用gulp进行构建时,出现错误。

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 这是我的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. 我无法弄清楚为什么当它显然是一个对象时,它认为dbConnection是一个命名空间。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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