Javascript 无法使用--out注释将typescript模块(.ts)文件合并到单个输出(.js)中:Getting Error
我是打字新手。我一直在尝试使用Javascript 无法使用--out注释将typescript模块(.ts)文件合并到单个输出(.js)中:Getting Error,javascript,typescript,typescript1.5,Javascript,Typescript,Typescript1.5,我是打字新手。我一直在尝试使用tsc--out命令连接typescript模块。但我犯了一些错误。没有关于错误的信息。下面是过程,我累了 .ts文件我有: Validation.ts: module Validation { export interface StringValidator { isAcceptable(s: string): boolean; } } ZipCodeValidator.ts: /// <reference path="V
tsc--out
命令连接typescript模块。但我犯了一些错误。没有关于错误的信息。下面是过程,我累了
.ts文件我有:
Validation.ts:
module Validation {
export interface StringValidator {
isAcceptable(s: string): boolean;
}
}
ZipCodeValidator.ts:
/// <reference path="Validation.ts" />
module Validation {
var numberRegexp = /^[0‐9]+$/;
export class ZipCodeValidator implements StringValidator {
isAcceptable(s: string) {
return s.length === 5 && numberRegexp.test(s);
}
}
}
错误:
error TS6053: File 'ΓÇÉout.ts' not found.
error TS6054: File 'sample.js' must have extension '.ts' or '.d.ts'
请让我知道解决方法。还有一个问题,有没有办法在gulp中连接typescript模块?我不会准确回答您,因为我没有使用
tsc
命令
但如果我是你,我会让它自动运行(比如吞咽):
简而言之:
- :tsc用于吞咽
- :允许您生成.map(链接.ts文件和.js文件)
- :允许您在管道中添加源文件。在这个过程中推送一些javascript文件是很有用的
- :concat所有文件
tsc--out
中使用了错误的破折号字符TypeScript编译器查看您的命令,而不是“使用文件调用tsc
Test.ts
,并输出到sample.js
”看到类似的内容:“使用3个文件调用tsc:--out
,sample.js
,Test.ts
”。然后它会查找这些文件并尝试编译它们
要解决此问题,只需复制并粘贴具有正确破折号字符的命令:tsc--out sample.js Test.ts
不知道为什么不接受它,它确实有效,是自动化构建过程的更好方法。谢谢你,我一直在努力了解如何将我的js构建为一个文件,但是sourcemaps到Typescript完好无损!
/// <reference path="Validation.ts" />
/// <reference path="LettersOnlyValidator.ts" />
/// <reference path="ZipCodeValidator.ts" />
// Some samples to try
var strings = ['Hello', '98052', '101'];
// Validators to use
var validators: { [s: string]: Validation.StringValidator; } = {};
validators['ZIP code'] = new Validation.ZipCodeValidator();
validators['Letters only'] = new Validation.LettersOnlyValidator();
// Show whether each string passed each validator
strings.forEach(s => {
for (var name in validators) {
console.log('"' + s + '" ' + (validators[name].isAcceptable(s) ? ' matches ' : ' does not match ') + name);
}
});
tsc --out sample.js Test.ts
error TS6053: File 'ΓÇÉout.ts' not found.
error TS6054: File 'sample.js' must have extension '.ts' or '.d.ts'
var gulp = require('gulp');
var typescript = require('gulp-typescript');
var sourcemaps = require('gulp-sourcemaps');
var addsrc = require('gulp-add-src');
var concat = require('gulp-concat');
gulp.task('tsc', function () {
return gulp.src(['*.ts']) // all your ts files here (check the path)
.pipe(sourcemaps.init())
.pipe(typescript({
sortOutput: true
}))
.js // compile with tsc, ordered with _reference.ts
.pipe(addsrc('external.js')) // add an external javascript file (if needed)
.pipe(concat('app.js')) // concat all in one file
.pipe(sourcemaps.write()) // generate the .map
.pipe(gulp.dest('dist')); // write all in the dist folder
});