我正在使用node v6.8.0,TypeScript v2.0.3,gulp v3.9.1和gulp-typescript v3.0.2。当我用gulp构建时,我得到一个错误。
这是我的代码
/// <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;
这是我得到的错误:
[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
这是我的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())
;
});
我无法弄清楚为什么当它显然是一个对象时,它认为dbConnection是一个命名空间。
答案 0 :(得分:0)
我将noEmitOnError: true
更改为noEmitOnError: false
,它仍然告诉我存在语义错误,但它构建并运行得很好。