Questions tagged [tsc]

0

votes
0

answer
4

Views

typscript compiler (tsc) throws error, but only when used in yarn script, otherwise works fine

So if I execute: tsc Everything compiles, no issues. Picks up patterns in tsconfig.json # inside package.json scripts: { "build" : "tsc" } $ yarn build Throws error. error TS6307: File '***' is not in project file list. Projects must list all files or use an 'include' pattern. error Command faile...
Sandwich
1

votes
1

answer
226

Views

Is there a type in @types/express for Express middleware functions

Right now I have this in a custom .d.ts file: import { Request, Response, NextFunction } from 'express'; export type MiddleWareFn = (req: Request, res: Response, next: NextFunction) => void; and I reference that file like so: router.use('/foo', function(req,res,next){}); however I am wondering if E...
Alexander Mills
1

votes
1

answer
610

Views

What's the difference between tsc (TypeScript compiler) and ts-node?

I'm very confused about the difference between tsc and ts-node. I'm learning TypeScript and I usually transpile server .ts files with tsc command. Now, I'm approaching nestjs framework, and I see that it uses ts-node. So what's the difference between the two? Which one should I use?
gremo
3

votes
2

answer
1.5k

Views

Getting TSC rate in x86 kernel

I have an embedded Linux system running on an Atom, which is a new enough CPU to have an invariant TSC (time stamp counter), whose frequency the kernel measures on startup. I use the TSC in my own code to keep time (avoiding kernel calls), and my startup code measures the TSC rate, but I'd rather ju...
Paul DeRocco
17

votes
4

answer
13.5k

Views

Is there a way to use npm scripts to run tsc -watch && nodemon --watch?

I'm looking for a way to use npm scripts to run tsc --watch && nodemon --watch at the same time. I can run this commands independently, but when I want run both of them, only the first one is executed. eg. if I have this script: "scripts": { "runDeb": "set NODE_ENV=development&& tsc --watch &&...
18

votes
2

answer
8.1k

Views

Mute/ignore TS2307 error from TypeScript tsc

Is there a way to mute the TS2307 error from the TypeScript tsc compiler? It makes it really hard to spot real/new errors and warnings as there are many TS2307 errors in our codebase. Update: This error occurs when an external module is imported without its type definition .d.ts being present. I'm a...
Peter V
4

votes
1

answer
2.3k

Views

How do I use the TypeScript compiler in the 'Watch output files' mode (tsc -w) on Windows?

The compiler version installed with the VS plugin doesn't have this option, but the version for node.js has. However I can't make this mode work on Windows. It creates empty files and doesn't compile anything. Is it a known bug? Can this be helped? I don't want to use heavy-weight VS, create a VS pr...
thorn
5

votes
1

answer
245

Views

TypeScripts transpiles files which are non-executable

It appears as though TypeScript is transpiling target files that are not executable. I have to run chmod u+x after transpilation to get the files to become executable. This is the case, even if they have a hashbang: #!/usr/bin/env node How can I tell TypeScript / tsc to create files which are execu...
Alexander Mills
4

votes
1

answer
385

Views

Missing TSC warning for invalid assignment

I'm trying to write a TypeScript type definition file for the node-serialport library. The library exports a parsers variable with two functions, raw and readline. The latter cannot be used as a parser directly - it produces a parser when invoked. This is a fragment of my first attempt at a type def...
provegard
5

votes
2

answer
1.4k

Views

Angular 2 AoT ngc does not generate any files

When I run the offline compiler ngc on an Angular 2 RC5 vanilla project created by angular-cli, it does nothing. Here's what I did Setup: ng new my-project cd my-project npm install @angular/compiler-cli [email protected] @angular/platform-server @angular/compiler Running the compiler ./node_modules/....
user6123723
5

votes
2

answer
302

Views

Use type definitions from .d.ts file without importing

I am migrating a web-application from plain Javascript to Typescript, and am compiling all separate files into a single one using the --outFile compiler option and /// directives. This is nice, because I can split my code up into multiple files without having to worry about a browser supporting imp...
iFreilicht
3

votes
2

answer
944

Views

Typescript sourcemaps using command-line Babel

I'm trying to get Babel to produce sourcemaps when run from the command line. The Babel docs around sourcemaps seem to be targeted more toward the gulp workflow and I'm not sure how that translates to the command line. I'm compiling my typescript using tsc -p ./src My tsconfig.json: { "compilerOpti...
zyzof
11

votes
4

answer
176

Views

TypeScript require one parameter or the other, but not neither

Say I have this type: export interface Opts { paths?: string | Array, path?: string | Array } I want to tell the user that they must pass either paths or path, but it is not necessary to pass both. Right now the problem is that this compiles: export const foo = (o: Opts) => {}; foo({}); does anyone...
Olegzandr Denman
2

votes
1

answer
1.7k

Views

Can't install tsc via Terminal in OS X

I'm trying to get tsc installed, but when I run it, I'm getting loads of errors. I've tried to reinstall node and npm at least three times now, but to no avail. I set the flag to verbose for my npm, and here's what I got: Mitch:~ mitch$ npm install -g typescript npm info it worked if it ends with ok...
Voz
5

votes
2

answer
3.1k

Views

Typescript compiler errors when including node.d.ts

I recently started switching form PHP to Node.js, and since I'm a huge Typescript fan, I'm using Typescript + Node.js. I had my sample compiling just fine when I started to scale up and really build my code. But then I ran into an issues. Whenever node.d.ts is referenced (with the reference doc comm...
GJK
2

votes
2

answer
1.3k

Views

TypeScript: How to replace imports with window objects?

I created a TypeScript module which requires a third-party library: import Dexie from "dexie"; namespace storage { ... } When I compile my TypeScript file, I get the following JavaScript output: "use strict"; var dexie_1 = require("dexie"); var storage; (function (storage) { ... })(storage || (stora...
11

votes
6

answer
5.6k

Views

TypeScript compile and keep comments

I like to have my comments intact in the resulting javascript file, by default the compiler removes them. Is there a tsc parameter for that? (The use case is to keep /// reference path's = ... for chutzpah unit testing. )
joeriks
2

votes
2

answer
1.3k

Views

TypeScript node sample won't compile

It seems everyone's got the sample to work, but mine just won't... I have nodejs 0.8.2 install in windows 7 64bit. Did a npm install -g typescript to get TypeScript support. Then I downloaded the source from TypeScript and tried the samples but I just can't get the node sample to compile. It returns...
user1600124
1

votes
1

answer
332

Views

TSC: what does --target ES3 compatibility flag do?

I installed typescript npm package: npm install typescript and ran node_modules\.bin\tsc doodle.ts -t ES3 Where doodle.ts has: var test = document.querySelector('.test'); It echoed back the same in output doodle.js. How to configure it so in the output, I get: var test = document.getElementsByClassN...
Annie
2

votes
1

answer
1.6k

Views

Receiving getExecuting FilePath error in TypeScript

I am using WebStorm for a node.js application developed using transpiled TypeScript. Whenever I run the tsconfig.json by selecting "compile all" from the TypeScript tab, I get the following error: Error:Initialization error (typescript). Cannot read property 'getExecutingFilePath' of undefined. Howe...
user1790300
5

votes
2

answer
12.7k

Views

Missing *.ts files (due to `npm link` ?)

I have this import statement in an Angular5 project: import {plugins, SCECodeGenType} from 'sce-plugins/code-generation'; this resolves to this path on my filesystem: /Users/.../suman-chrome-extension/node_modules/sce-plugins/code-generation/index.d.ts When building the app with ng build -w, I get t...
Alexander Mills
2

votes
1

answer
94

Views

TypeScript type representing everything but undefined

I have a function like so: export const logToStdout = function(v: NotUndefined){ console.log(JSON.stringify({ marker: '@json-stdio', value: v }); } what I would like to have is a definition for NotUndefined that is everything but undefined. You can see the problem when running: console.log(JSON.stri...
2

votes
1

answer
35

Views

Duplicate string values in TS enum does not cause compilation error?

I have this in a TypeScript enum: export enum LMXLockRequestError { MaxRetries = 'bad_args', BadArgumentsError = 'bad_args', } this doesn't seem to cause a compilation error. It transpiles to this: var LMXLockRequestError; (function (LMXLockRequestError) { LMXLockRequestError["MaxRetries"] = "bad_ar...
Alexander Mills
6

votes
1

answer
1k

Views

How do I get TypeScript to bundle a 3rd party lib from node_modules?

I would like the TypeScript Compiler to use node_modules/firebase/firebase.d.ts to typecheck my code and also bundle node_modules/firebase/firebase.js into some of the files where I import things from firebase. I understand there are many options which will do this for me, but I'd like to keep a min...
Andrey Fedorov
2

votes
1

answer
243

Views

webpack not able to bundle files when tsc is

I'm having some trouble getting webpack to build my files. it just spits a bunch of errors, all of the same form, saying: ERROR in ./node_modules/typescript-rest/dist/server.js Module not found: Error: Can't resolve 'typescript-ioc/es6' in '/Users/Jack/NODE/ts-rest-session/node_modules/typescript-re...
Jack Bliss
2

votes
1

answer
190

Views

What's the benefit of using TypeScript with Babel 7+

The release of Babel 7+ introduced TypeScript support. But what are the benefits of compiling TypeScript with Babel rather than using the standard TypeScript compiler (tsc)?
Francesco Borzì
12

votes
2

answer
20.9k

Views

Run a npm script from gulp task

How to run a npm script command from inside a gulp task? package.json "scripts": { "tsc": "tsc -w" } gulpfile.js gulp.task('compile:app', function(){ return gulp.src('src/**/*.ts') .pipe(/*npm run tsc*/) .pipe(gulp.dest('./dist')) .pipe(connect.reload()); }); I want to do this because running npm r...
lbrahim
6

votes
4

answer
4.7k

Views

TS2307: Cannot find module 'ionic/ionic'

When trying to use tsc with my ionic2 project, i am getting the following error on a typescript file. The Error: TS2307: Cannot find module 'ionic/ionic' The Code: import {Page} from "ionic/ionic" //error happens on this line @Page({ templateUrl: 'app/list/list.html', }) export class ListPage { cons...
prolink007
2

votes
2

answer
253

Views

upgrade typescript playground on ace to 1.0 RTM

I've been bumbling around attempting to upgrade a fork of Basarat Ali Syed's excellent typescript editor project to Typescript 1.0 RTM. Out of the box the project works without issue however it's using a year old version of typescript and the compiler api has changed quite a bit since then. To updat...
Jeremy Danyow
7

votes
5

answer
446

Views

Migrate gulp process to include typescript

I am updating the build process for an Angular 1.5.8 application, to allow development on Typescript. After an over-complicated experience with Grunt, the current build process is simple and only uses Gulp and Browserify to build two bundles: my-lib.js and my-app.js. This way, the library, which is...
Gerardo Lima
3

votes
1

answer
6.9k

Views

Angular 2 beta “npm run tsc” Command fails

I can't seem to compile my Typescript using the npm run ts" command. What i find a little weird is that i can run the npm start and that way it compiles and runs fine. The log is below: 0 info it worked if it ends with ok 1 verbose cli [ 'node', '/usr/local/bin/npm', 'run', 'tsc' ] 2 info using np...
Habber
32

votes
2

answer
3.2k

Views

TypeScript: compiling removes unreferenced imports

In our project we're using RequireJS as our module loader. Some of our modules will influence global libraries, and hence won't be directly used within the module they are referenced in. Example: define(['definitely/goingto/usethis/','just/referencingthis/forpackaging'], function(useThis) { useThis....
thomaux
7

votes
3

answer
1.1k

Views

Create Electron Menu in TypeScript?

Just started a simple Electron app using TypeScript and I'm trying to get my custom menu setup. I followed the example in JS, but the line menu = Menu.buildFromTemplate(template); fails to compile with the error: main.ts(109,35): error TS2345: Argument of type '({ label: string; submenu: ({ role: st...
stwissel
3

votes
1

answer
476

Views

Map array to an interface

Say I have an array that looks like this: const options = [ { name: 'foo', type: 'boolean' }, { name: 'bar', type: 'string' }, { name: 'bar', // should be baz not bar type: 'number' } ] I am looking to use this array as an interface which would look something like this: export interface Opts { foo:...
3

votes
1

answer
60

Views

Ignore multiple results of a destructuring in typescript

I'm using typescript destructuring as follows: const props = new Map(); props.set(bill, [n, a, l, g]); // ... // Want to access location and gender of bill. const [n, a, l, g] = props.get(bill); console.log(l + g); But this violates the noUnusedLocals compiler option, so what I really want is: const...
Blake H
1

votes
1

answer
1k

Views

Typescript compiler option alwaysStrict unavailable?

The Compiler Options page on Typescript website lists the --alwaysStrict option, it's supposed to tell the compiler to emit "use strict" statements in the output. Note that I'm working in Visual Studio Code. I added the option in my tsconfig.json: { "compilerOptions": { "alwaysStrict": true, //... b...
Alex
4

votes
3

answer
1.7k

Views

npm doesn't update tsc version

Typescript is updated using the following command: npm install typescript -g And latest version 2.4.2 is installed correctly and I can verify it by looking the path shown by folloing command: npm list typescript -g but the following command shown older version (1.0.3.0) : tsc -v Also looked in TEMP...
mehran
35

votes
5

answer
26.1k

Views

How to find module “fs” in MS Code with TypeScript?

I'm running on a MacBook Air. I installed MS Code as an IDE and also have TypeScript installed. I have a simple file with just this line: import fs = require('fs'); I'm getting a red squiggly under the 'fs' inside the parenthesis and the error message is [ts] Cannot find module 'fs'. The file has a...
Brick
36

votes
6

answer
28k

Views

How can I pass multiple source files to the TypeScript compiler?

TypeScript is designed for large-scale JavaScripty projects which typically consist of multiple internally produced files along with externally produced libraries. How does the TypeScript compiler (tsc) expect you to provide it with the complete set of files that make up a project?
CCoder
3

votes
1

answer
1.1k

Views

How to use a compiled TypeScript class in Javascript

Imagine I have this simple TypeScript class, Animal.ts: export default class Animal { constructor(public name : string) { } } With this tsconfig.json file: { "compilerOptions": { "target": "es5", "module": "commonjs", "strict": true }, "files": [ "Animal" ] } How can I use the compiled version of th...
Titulum

View additional questions