我有以下代码:
let statistics = this.video.getStatistics();
let currentLikeCount : number = statistics!.getLikeCount() ? statistics.getLikeCount() : 1;
Run Code Online (Sandbox Code Playgroud)
但是,在使用Typescript进行编译时出现以下错误
error TS2322: Type 'number | null' is not assignable to type 'number'.
Run Code Online (Sandbox Code Playgroud)
我的条件检查以查看like count是否为null,如果是,则将其分配给一个数字,但typescript仍然抱怨它可能为null.
如何正确地将相似的数量分配给数字?
我正在尝试运行以下Gulp任务来编译Sass文件,使用OS X Yosemite 10.5.5上的插件gulp-compass.
var path = require("path");
var gulp = require("gulp");
var compass = require("gulp-compass");
gulp.task("compile2013Base", function() {
var projectPath = path.join(__dirname, '../../ ');
gulp.src(['../sass/desktop/css/2013/*.scss']).pipe(compass({
project: projectPath,
css: 'htdocs/assets/css/2013/',
sass: 'sass/desktop/css/2013'
})).on('error', errorHandler).pipe(gulp.dest('../../htdocs/assets/css/2013/'));
});
function errorHandler (error) {
console.log(error.toString());
this.emit('end');
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试运行任务时gulp compile2013Base,我收到以下错误:
> gulp compile2013Base
[13:39:06] Using gulpfile [**redacted**]/scripts/js/gulpfile.js
[13:39:06] Starting 'compile2013Base'...
[13:39:06] Finished 'compile2013Base' after 9.07 ms
events.js:85
throw er; // Unhandled 'error' event
^
Error: spawn /usr/bin/compass ENOENT
at exports._errnoException (util.js:746:11)
at Process.ChildProcess._handle.onexit (child_process.js:1053:32) …Run Code Online (Sandbox Code Playgroud)