无法使用--out将打字稿模块(.ts)文件合并为单个输出(.js)文件注释:出现错误 [英] Unable to concat typescript modules (.ts) files into single output(.js) using --out Comment: Getting Error

查看:339
本文介绍了无法使用--out将打字稿模块(.ts)文件合并为单个输出(.js)文件注释:出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Typescript的新手.我一直在尝试使用tsc --out命令来连接打字稿模块.但是我遇到了一些错误.没有有关该错误的信息.下面是过程,我很累.

I am new to Typescript. I've been trying to concatenate typescript modules by using the tsc --out command. But I'm getting some error. There is no information about the error. Below is the process, I've tired.

.ts文件:

Validation.ts:

Validation.ts:

module Validation {  
    export interface StringValidator {
       isAcceptable(s: string): boolean;
    }
}

ZipCodeValidator.ts:

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);
        }
    }
}

LettersOnlyValidator.ts:

LettersOnlyValidator.ts:

/// <reference path="Validation.ts" />
module Validation {
    var lettersRegexp = /^[A‐Za‐z]+$/;
    export class LettersOnlyValidator implements StringValidator {
        isAcceptable(s: string) {
            return lettersRegexp.test(s);
        }
    }
}

Test.ts:

/// <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命令:

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' 

请让我知道解决方法.还有,还有什么方法可以在gulp中连接typescript模块?

Please let me know the way to resolve. And one more, is there any way to concat the typescript module in gulp?

推荐答案

您似乎在tsc --out中使用了错误的破折号.
TypeScript编译器查看您的命令,而不是 "使用文件Test.ts调用tsc并将其输出到sample.js" 看到的是 使用3个文件调用tsc:--outsample.jsTest.ts" .然后,它会寻找这些文件并尝试对其进行编译.

It looks like you're using wrong dash character in your tsc --out.
TypeScript compiler looks at your command and instead of "invoke tsc with file Test.ts and output to sample.js" sees something along the lines of "invoke tsc with 3 files: --out, sample.js, Test.ts". It then looks for these files and tries to compile them.

要解决此问题,只需复制并粘贴带有正确破折号的命令即可:
tsc --out sample.js Test.ts

To fix the problem, just copy&paste the command with the correct dash character:
tsc --out sample.js Test.ts

这篇关于无法使用--out将打字稿模块(.ts)文件合并为单个输出(.js)文件注释:出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆