61024

Unable to concat typescript modules (.ts) files into single output(.js) using --out Comment: Getting

Question:

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 files I have:

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

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 command:

tsc --out sample.js Test.ts

Error:

error TS6053: File 'ΓÇÉout.ts' not found. error TS6054: File 'sample.js' must have extension '.ts' or '.d.ts'

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

Answer1:

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

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

Answer2:

I won't answer you exactly because i don't use the tsc command.

But if I were you, I would make it automatic (with Gulp for example) :

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

<strong>In short :</strong>

<ul><li><a href="https://github.com/ivogabe/gulp-typescript" rel="nofollow">gulp-typescript</a> : <strong>tsc</strong> for gulp</li> <li><a href="https://github.com/floridoo/gulp-sourcemaps" rel="nofollow">gulp-sourcemaps</a> : allows you to generate the <strong>.map</strong> (to link between the .ts files and the .js files)</li> <li><a href="https://github.com/urish/gulp-add-src" rel="nofollow">gulp-add-src</a> : allows you to <strong>add sources files in the pipe</strong>. It's usefull to push some javascript files in the process.</li> <li><a href="https://github.com/wearefractal/gulp-concat" rel="nofollow">gulp-concat</a> : <strong>concat</strong> all the files</li> </ul>

Recommend

  • Need Help in Creating a Cookie
  • dynamically generted html table cannot get selected td value
  • how can i know what are the shown parts of the html through javascript
  • How to get the Index of First Character from a string contains numeric values using javascript
  • Adding objects over camera view in app (Swift 3) not under camera view?
  • Octal literals are not available when targeting ECMAScript 5 and higher
  • Angular 2 Form Async validation ajax call on every keypress
  • Zend\\ServiceManager\\ServiceManager::get was unable to fetch or create an instance for getAlbum
  • How to remove special characters in file names?
  • PHP Explode from first number (integer)
  • How to store pointer to S3 objects in Amazon SimpleDB?
  • Parsing tokens with PLY
  • Imagemagick set interline spacing?
  • How to not let setText crash/freeze my whole application? Even using SwingUtilities and Threads?
  • Google API client bug, sending locations
  • Zend Framework 2 - Building a simple form with Validators
  • Finding number of samples in a .wav header
  • what is browser's native support according to selenium webdriver
  • Laravel 5.1 Multitenancy setup
  • record audio in HTML / js without Flash?
  • how to set id for each item in ListView
  • Google Maps getMap returns null
  • Is mp4 stream able with ffserver?
  • Cannot invoke my method on the array type int[]
  • Regarding starting the threads on a condition
  • How to specify input and output paths from cmd.exe for a PowerShell script?
  • What does 'Language neutral' mean with regard to MAKELANGID?
  • How to access EntityManager inside Entity class in EJB3
  • Display issues when we change from one jquery mobile page to another in firefox
  • Deselecting radio buttons while keeping the View Model in synch
  • Opengl-es onTouchEvents problem or a draw problem? [closed]
  • JSON with duplicate key names losing information when parsed
  • When should I choose bucket sort over other sorting algorithms?
  • Jquery - Jquery Wysiwyg return html as a string
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Change div Background jquery
  • apache spark aggregate function using min value
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • How to push additional view controllers onto NavigationController but keep the TabBar?