Questions tagged [tsc]

tsc is a compiler for converting TypeScript into plain JavaScript.

tsc is a compiler for converting TypeScript into plain JavaScript targeting either the ECMAScript 3 or ECMAScript 5 specifications.

927 questions
20
votes
3 answers

Programmatically compile typescript in C#?

I'm trying to write a function in C# that takes in a string containing typescript code and returns a string containing JavaScript code. Is there a library function for this?
mpen
  • 272,448
  • 266
  • 850
  • 1,236
19
votes
1 answer

Is there a way to automatically fix `import type` errors on TypeScript when using "importsNotUsedAsValues": "error"?

I have a big TypeScript project that I started without using the "importsNotUsedAsValues": "error" compiler flag. As the project grew, I decided it is a good idea in terms of optimization to enforce import type when an import is not being used as a…
Bruno Finger
  • 2,105
  • 3
  • 27
  • 47
19
votes
7 answers

How do I compile Typescript at Heroku postinstall?

Instead of uploading the precompiled dist directory, I want to compile src at server side instead. Here are my scripts inside package.json: "scripts": { "test": "echo \"No test specified\" && exit 0", "start": "node dist/app.js", …
Talha Talip Açıkgöz
  • 1,821
  • 4
  • 15
  • 28
18
votes
1 answer

tsc --build vs tsc --project

I have a monorepo where I am converting a subproject to TypeScript. In my npm scripts I have: "build-proj1":"tsc --build ./proj1/tsconfig.json" It works, but for some reason, I noticed that it is extremely slow. When I change it…
Roman
  • 1,727
  • 1
  • 20
  • 28
18
votes
2 answers

Convert Typescript with JsDoc

Can I convert TypeScript file to JavaScript file with JSDoc? For example, if I have this main.ts file: let x: string = "hello"; // This could be number or array of numbers let y: number | number[]; It will be converted to something like this…
17
votes
4 answers

Generate one declaration file for TypeScript library

I developed a library, which also contains TypeScript files, in Visual Studio 2013. The files are compiling correctly to JS files (AMD). What I want is to create a single declaration file for this lib, but this does not work: tsc --declaration…
bobschi
  • 325
  • 1
  • 3
  • 13
16
votes
5 answers

Unable to uninstall typescript globally through npm

I've installed typescript 2.4.1 on my system globally (tsc -v gives me version 2.4.1). I want to uninstall it as I want to go to version 2.3.4 for some of my e2e tests to work. But right now I'm unable to uninstall it. I tried to uninstall through…
Omar Bahir
  • 1,237
  • 5
  • 20
  • 48
16
votes
1 answer

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…
Andrey Fedorov
  • 9,148
  • 20
  • 67
  • 99
15
votes
1 answer

Ignore *.js and *.jsx files with tsconfig.json

This is what we have tried: { "compilerOptions": { "target": "esnext", "moduleResolution": "node", "allowJs": true, "jsx": "react" }, "include": [ "src/**/*" ], "exclude": [ "src/**/*.js", "src/**/*.jsx", …
Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467
15
votes
2 answers

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…
iFreilicht
  • 13,271
  • 9
  • 43
  • 74
15
votes
2 answers

TypeScript via tsc command: Output to single file without concatenation

Is there a way of compiling single .ts file to different directory? The only way from the manual command of compilation to different directory is via --out command, but it also does concatenation of dependent files, which I don't want: --out…
Vojtěch
  • 11,312
  • 31
  • 103
  • 173
14
votes
4 answers

Fixing TS2688: Cannot find type definition file in node_modules

When running tsc, I am getting many TS2688: Cannot find type definition file for 'someLibrary' These libraries came from node_modules. I have tried to exclude node_modules and skipLibCheck in tsconfig, but none of them works for me. Any idea why is…
Brian Law
  • 460
  • 1
  • 4
  • 18
14
votes
5 answers

How to resolve Chicken/Egg situation with `tsc` and `npm install`?

So I have the standard folder structure dist/ src/ where src has my .ts files and dist has my .js files. (I have "outDir":"dist" in my tsconfig.json file, and "includes" set to 'src'). Note that 'dist' is in my gitignore file, so it is not in…
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
14
votes
4 answers

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…
Alexander Mills
  • 90,741
  • 139
  • 482
  • 817
13
votes
2 answers

How to have top level await in typescript (switch from commonjs to esnext) without having to change all imports to have .js ending

I would like to have top level await in my typescript nodejs project. My tsconfig used to look like this: { "compilerOptions": { "target": "es2017", "module": "commonjs", "lib": [ "dom", "es6", "es2017", …
sev
  • 1,500
  • 17
  • 45