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
12
votes
5 answers

Error: Package exports for tslib do not define a valid '.' target

I literally made no changes to code, and suddenly I woke up to this error one day, backend: internal/modules/cjs/loader.js:454 backend: const e = new Error(`Package exports for '${basePath}' do not define a ` + backend: ^ backend:…
Kumar Abhirup
  • 308
  • 1
  • 4
  • 16
12
votes
2 answers

Declaration will not emit due to private name usage

I'm trying to convert a project to TypeScript, and I have most things set up, but I'm still struggling with getting the last few pieces put together. I want to be able to use this TypesScript project from a normal JavaScript project, so my…
iceblueorbitz
  • 920
  • 1
  • 7
  • 17
12
votes
1 answer

Why is ES7/array polyfill needed despite the tsconfig target is set to ES5

I have the following settings in thetsconfig.json. I added "es2017" to use Array.includes.: { "compilerOptions": { "lib": [ "es6", "es2017", "dom" ], "module": "es6", "target": "es5" } } Now, I realized, that I…
BuZZ-dEE
  • 6,075
  • 12
  • 66
  • 96
12
votes
1 answer

Where should I put the index.d.ts file?

I am writing a nodeJS service that uses a bunch of npm modules without @types. The tsc error message tells me that I need to add index.d.ts file, but it doesn't tell me where to put it. My helper.spec.ts file which also imports the same modules also…
Jake
  • 11,273
  • 21
  • 90
  • 147
12
votes
1 answer

How to copy package.json in dist or build folder when running tsc (TypeScript compiler)

I have a TypeScript React component that uses a package.json file (see screenshot) and I run tsc in order to transpile it to es5 in my dist folder but the package.json file doesn't get copied. Please note that in the screenshot I manually copied it…
Gab
  • 2,216
  • 4
  • 34
  • 61
12
votes
1 answer

noImplicitAny not working Typescript

In my root folder I have tsconfig.json file which looks like this: { "compilerOptions": { /* Basic Options */ "target": "es2015", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or…
Vladimir Djukic
  • 925
  • 2
  • 9
  • 28
11
votes
5 answers

ts-node-dev not restarting when changes made

Here are my files : package.json : "scripts": { "generate-interfaces": "ts-node src/cli/generate-interfaces.ts", "dist": "npm run generate-interfaces && rm -rf dist && tsc && cp -r static/ dist/ && cp -r resource/ dist/", "prestart": "npm run…
Himanshu Teotia
  • 2,126
  • 1
  • 27
  • 38
11
votes
1 answer

TypeScript compilation of RequireJS module generates line Object.defineProperty(exports, "__esModule", { value: true }); How to get rid of it?

This is how my tsconfig.json file looks: { "compileOnSave": true, "compilerOptions": { "module": "amd", "noImplicitAny": false, "removeComments": false, "preserveConstEnums": true, "strictNullChecks":…
John Doe
  • 328
  • 3
  • 12
11
votes
2 answers

In vscode errors generated by a task with isWatching are not always cleared after they have been fixed

I'm using a gulp task in vscode (0.9) to try to get errors from both typescript and tslint. The gulp task is watching for changes on my ts files and run both the gulp-tslint and gulp-typescript on changes. I also defined a task in vscode tasks.json…
Sebastien
  • 5,506
  • 4
  • 27
  • 37
11
votes
3 answers

How to compile an Angular2 TypeScript application to a single file?

I realize that I can compile my application with tsc my_app.ts --target system and it will generate a SystemJS-wrapped file for each imported module, which is awesome, but it generates anonymous (nameless) functions, so I can't just concatenate them…
Gray Fox
  • 673
  • 1
  • 8
  • 21
11
votes
5 answers

Does TypeScript provide an explicit Public API for NodeJS Module Access?

From within a node app I would like to do: var typeScript = require('typescript'); typeScript.compile('...') I'm looking to implement the compiler into a build system but without access to a public API (typescript.compile, etc) this is…
cnp
  • 1,010
  • 2
  • 9
  • 20
10
votes
0 answers

Enable tslint/eslint rule TS2339 (Property 'x' does not exist on type 'y')

While every topic I can find wants to fix or disable the TS2339 error, I'm trying to get the eslint rules in-sync with typescript rules and I would like to enable it. In looking at the typescript-eslint project, I cannot seem to find how to enable…
anAgent
  • 2,550
  • 24
  • 34
10
votes
0 answers

Why to use intersection with empty object type and mapped type in TypeScipt

In the source code of ts-toolbelt, there is often an intersection of an empty object and a mapped type. For what purpose is this done? export type ReadonlyFlat = { +readonly [K in keyof O]: O[K]; } & {}; // there export type OptionalFlat =…
Alexander Pankin
  • 475
  • 2
  • 10
10
votes
3 answers

Property 'trimLeft' does not exist on type 'string'. Lib: ["dom", "es2018"]

I am getting this Error when running the following code let foo = ' foo ' console.log(foo.trimLeft()) //foo.trimStart() works neither I know most of the solutions in the internet say, that I have to fix my tsconfig.json to include…
uloco
  • 2,283
  • 4
  • 22
  • 37
10
votes
1 answer

node.js: Unexpected token {

So I have a unit test written for mocha using TypeScript. I am trying to run it using gulp (which doesn't really play a part here). I get the following exception: (function (exports, require, module, __filename, __dirname) { import { assert } from…
Jeff Saremi
  • 2,674
  • 3
  • 33
  • 57