It's quite interesting that I couldn't find this information in the documentation - is there a simple way to instruct tsc
to compile all files within a directory and its subdirectories without setting up a complete tsconfig.json
configuration?
It's quite interesting that I couldn't find this information in the documentation - is there a simple way to instruct tsc
to compile all files within a directory and its subdirectories without setting up a complete tsconfig.json
configuration?
As far as I am aware, there is no way to use tsc
from the command line without a tsconfig.json
file unless you specify each file individually like this:
tsc MyFile1.ts MyFile2.ts MyFile3.ts
However, it seems that you can simply create an empty tsconfig.json
file (just containing {}
) in the root of your TypeScript directory and it will achieve the desired result. According to https://github.com/Microsoft/TypeScript/wiki/tsconfig.json:
If no
"files"
property is present in atsconfig.json
file, the compiler will automatically include all TypeScript (*.ts or *.tsx) files in the current directory and its subdirectories.
Using globs can simplify your TypeScript compilation command.
tsc x/file1.ts x/file2.ts x/file3.ts
This command is essentially the same as using a glob pattern:
tsc x/*.ts
In the event that you come across a tsconfig.json file in your project directory, simply input
tsc and all of your typescript files will be compiled within the same folder. If for some reason you do not have a tsconfig.json file, you can create one by typing:
tsc -init
While some may consider it excessive, I recently created a PowerShell function to be used in Visual Studio Code as a task;
function CompileTypeScriptFiles($folder) {
$tsFiles = Get-ChildItem $folder -Filter "*ts" -Recurse
$tsFiles | ForEach-Object {
$tsFile = $_.FullName;
$options = $tsFile + " --outDir js --sourceMap"
Start-Process "tsc" $options
}
}
For those utilizing Windows, the for
loop is essential:
for %f in (./path/*.ts) do npx tsc "./path/%f" --lib es2018 --outDir ./path/bin
Remember to double up on the %
if utilizing it within a bat
file:
for %%f in (./path/*.ts) do npx tsc "./path/%%f" --lib es2018 --outDir ./path/bin
All types of files can be constructed, including:
tsc ./**/*.ts
For those using Linux/Mac, a workaround is to execute the following command:
pushd dir && tsc && popd
It appears that a tsconfig.json file is required in the specified directory.
To keep this brief, the issue I'm facing is an extension of a Stack Overflow question regarding passing page-level variables into an Angular 2 app service. Following Gunter's advice from the provided SO question, I attempted to pass a JavaScript ...
Snippet of HTML code: <li class="dropdownfilter" *ngIf="this.arr.inclues('Male')" (click)="getValueGender('Male',1,)" [(ngModel)]="M"><a>Male</a></li> I encountered the following error: ERROR Error: No value a ...
I'm currently working on a drink tracking application. Users have the ability to add drinks, but there is also a drink limit feature in place to alert them when they reach their set limit. A modal will pop up with options to cancel or continue adding ...
Is it possible to retrieve the current active page name within the app.component.ts file in Ionic without having to add code to any other pages? ...
As someone who is new to Typescript, I recently came across the following syntax: interface Foo { // what does age signify and // what if it is not optional i.e () => string, age:number; (): () => string, age?: number; } From what I ...
When working with Angular, I have the need to call certain functions that will return a value based on the current page routing. These functions are currently located within the element that needs to be changed by the route's component. I know how to ...
When looking at the following code, Typescript is flagging an error on <HeaderInner>: [ts] Type '{ children: Element; }' has no properties in common with type 'IntrinsicAttributes & Pick & Partial>, "className"> & ...
Encountering an interesting TS error in the code snippet below: interface Bar { pictureType: "X" | "Y" } interface RT { output: Bar[] } const func = (): RT => { const list = [{ pictureType: 'X', }] r ...
Encountered an issue with my typings.d.ts file Error TS2403: Subsequent variable declarations must have the same type. Variable 'module' is expected to be of type 'NodeModule', but is currently of type '{id:string}'. declare ...
After using react-testing-library and @testing-library/jest-dom/extend-expect, I decided to install Cypress. However, I now face Typescript errors on all my jest matchers: Property 'toEqual' doesn't exist on type 'Assertion'. Did ...
Can you explain the functionality of this code snippet? const content : string = functionThatReturnsAString(); const blob = new Blob([content]); What does the [string] represent in this code? What is the output, and which constructor can it be passed as ...
Seeking insight on how to log information, debugging details, and error messages into a file (such as app.log or error.log) using typescript-logging for Angular. Alternatively, is there a more efficient method to log debug/info/errors in Angular 11? I have ...
My server is written in TypeScript, built with rollup and runs on node. Currently, I have numerous tests including unit tests that import and test specific entities, as well as end-to-end tests that start the server (with database and other components) and ...
Is there a way to remove the array elements cctype, cctypologycode, and amount if they are empty? What would be the most efficient approach? { "ccInput": [ { "designSummaryId": 6, "CCType": "A", "CCTypologyCode": "A", "Amount ...
Looking to implement a type guard as an object method? I have an array of objects with similar data structures, but crucial differences that need to be checked and guarded using TypeScript. interface RangeElement extends Element { value: number; } inter ...
I have a string that looks like this: "[111-11] text here with digits 111, [222-22-22]; 333-33 text here" and I am trying to parse it so that I can extract the code [111-11], [222-22-22], [333-33] along with their respective text descriptions. The challeng ...
Is there a way to retrieve the value of the input field [newUser] when clicking on the button and executing the action [onAddUser()] in the .ts file? <input type="text" ng-model="newUser" style="text-align:center"/> <button (cl ...
I am facing an issue in my code where I want to show and hide an image through a link when a button is clicked. Currently, when I click the button, the image opens in a new tab in Chrome instead of displaying it on my app's page. I need to link the UR ...
Previously, we built a website last year using the following versions: node v6.9.1 npm v3.10.8 angular-cli v1.0.0-beta.24 typescript v2.1.4 The application was successfully created by the previous developer. However, after setting up these versions and ...
Could someone provide an instance of an object that matches the TypeScript type below? I'm a bit confused because I've only worked with interfaces before and have only seen square brackets. type Hash = { (data: Uint8Array): Uint8Array blockLe ...