Compiling Typescript upon saving in Sublime Text 3

Seeking a solution: How can I get Sublime Text 3 to automatically compile Typescript code when I save it? Having to switch between the terminal and Sublime is getting tedious. Appreciate any advice, thank you!

Answer №1

Unsure how to save it on command, but you can achieve it by pressing ctrl+b. To make this method functional:

  1. Head to Tools->Build System->New Build System
  2. Copy and paste the code below:

    {
        "cmd": ["tsc","$file"],
        "file_regex": "(.*\\.ts?)\\s\\(([0-9]+)\\,([0-9]+)\\)\\:\\s(...*?)$",
        "selector": "source.ts",
    
        "windows": {
            "cmd": ["tsc.cmd", "$file"]
        }
    }
    
  3. Save it as "myTypeScript.sublime-build"

  4. Go to Tools->Build System and select the created build system "myTypeScript.sublime-build"

  5. To compile, simply press ctrl+b

You can find further explanation and guidance here

Answer №2

To compile your .TS files, open a terminal window in the folder where they are located and run 'tsc -w' to monitor changes and automatically compile them into .js files. Make sure you have the latest version of TypeScript installed for Node.js. Keep the terminal window open until you're done working. There's no need for any "compile on save" feature as it's not always reliable. Additionally, the TypeScript package in Sublime Text 3 is outdated.

Answer №3

Appreciate the help! Initially, I thought the solution was only for a single file. However, realizing I had multiple scripts in the folder, I sought out an alternative on the internet. Just in case someone else encounters this issue:

  1. Begin by creating a new file within the directory where all scripts are stored (in my scenario, it's /js) and name it tsconfig.json
  2. Insert the following code into the file:
    {
    "compilerOptions": {
        "emitDecoratorMetadata": false,
        "module": "commonjs",
        "target": "ES5"
    },
    "files":["your_script_0.ts", "your_script_1.ts"],
    "exclude": [
        "node_modules"
    ]
    }

  3. To proceed, navigate to the source folder in the terminal (in my situation, it's /js) and utilize these commands:

    • for one-time compilation: tsc -p .
    • for compiling upon saving changes: tsc -w


Feel free to point out any mistakes or improvements regarding the command usage. Nonetheless, this approach has proven effective for me.

Answer №4

Attention all sublime text enthusiasts!

  1. First, get the package controller from this link.
  2. Next, launch sublime text and hit ctrl+shift+p, then type "install package" and hit enter.
  3. Type in Sublimeonsavebuild and press enter.
  4. Navigate to
    preferences > package settings > Sublimeonsavebuild > setting - user
    , paste in the code provided below, and save.
{
    "filename_filter": "(/|\\\\|^)(?!_)(\\w+)\\.(ts|sass|less|scss)$",
    "build_on_save": 1
}
  1. Go to
    tools > build system > new build system
    , paste in the following code, save it as "Typescript", and select this build option.
{
    "cmd": ["tsc","$file"],
    "file_regex": "(.*\\.ts?)\\s\\(([0-9]+)\\,([0-9]+)\\)\\:\\s(...*?)$",
    "selector": "source.ts",

    "windows": {
        "cmd": ["tsc.cmd", "$file"]
    }
}
  1. You're all set! Your .ts file will now automatically compile into a .js file every time you save it.
  2. Enjoy the seamless process!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can we create an intersection type of Records by pairing keys with tuples or unions of values in a one-to-one correspondence?

If I have tuples similar to this for keys and values: type Keys = ['North', 'East', 'South', 'West']; type Values = ['n', 'e', 's', 'w']; Is there a way to achieve a structure ...

Tips for sorting queries within a collection view in Mongoose:

I am working with Mongoose and creating a view on a collection. NewSchema.createCollection({ viewOn: originalModel.collection.collectionName, pipeline: [ { $project: keep.reduce((a, v) => ({ ...a, [v]: 1 }), {}), }, ], ...

Navigate objects by typing

I am in search of a type that can describe any path through an object starting from the top (root) properties all the way down to every leaf property in the form of a string array. The following are the key characteristics required: The object's stru ...

`Unable to upload spreadsheet file in xlsx format`

I'm currently working on implementing a feature to export data as xlsx files. I have been successful in exporting CSV and PDF formats, but encountered issues with the xlsx format due to dynamic imports. export const exportToXlsx = async ( gridElemen ...

Setting the [required] attribute dynamically on mat-select in Angular 6

I'm working on an Angular v6 app where I need to display a drop-down and make it required based on a boolean value that is set by a checkbox. Here's a snippet of the template code (initially, includeModelVersion is set to false): <mat-checkbo ...

billboard.js: The 'axis.x.type' property is conflicting with different data types in this context

axis: { x: { type: "category" } }, An issue has arisen: The different types of 'axis.x.type' are not compatible with each other. The value of 'string' cannot be assigned to '"category" | &qu ...

Tips for making the onChange event of the AntDesign Cascader component functional

Having an issue with utilizing the Cascader component from AntDesign and managing its values upon change. The error arises when attempting to assign an onChange function to the onChange property of the component. Referencing the code snippet extracted dire ...

Caution: The file path in node_modules/ngx-translate-multi-http-loader/dist/multi-http-loader.js relies on the 'deepmerge' dependency

My micro-frontend angular project is using mfe (module federation). I recently updated it from angular 13 to 14 and encountered some warnings such as: node_modules\ngx-translate-multi-http-loader\dist\multi-http-loader.js depends on ' ...

Encountering the following error message: "E11000 duplicate key error collection"

Currently, I am in the process of developing an ecommerce platform using the MERN stack combined with TypeScript. As part of this project, I am working on a feature that allows users to provide reviews for products. The goal is to limit each user to only o ...

Declare the variable as a number, yet unexpectedly receive a NaN in the output

I'm facing an issue with a NaN error in my TypeScript code. I've defined a variable type as number and loop through an element to retrieve various balance amounts. These values are in the form of "$..." such as $10.00 and $20.00, so I use a repla ...

Retrieve identification details from a button within an ion-item located in an ion-list

<ion-list> <ion-item-group *ngFor="let group of groupedContacts"> <ion-item-divider color="light">{{group.letter}}</ion-item-divider> <ion-item *ngFor="let contact of group.contacts" class="contactlist" style="cl ...

After updating next.config, the NextJS + NextAuth middleware doesn't seem to be triggered

I'm currently utilizing <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b0ded5c8c49dd1c5c4d8f0849e81889e87">[email protected]</a> & <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemai ...

What is the best way to pass a specific property from a parent component to a child component in Angular when a button is clicked?

Hey there, I'm looking for a way to pass a single property (groupId) from a parent component to a child component. In this case, my child component is using ngx-bootstrap modal. Is there a solution available for this scenario? Essentially, I need to i ...

Connecting an Angular application to a URL hosted on localhost

I am currently working on an Angular project where one of the links needs to redirect to a different website. During development, this link points to a localhost URL like localhost:4210. However, due to security reasons in Angular, using such URLs is cons ...

Production environment sees req.cookies NEXTJS Middleware as undefined

Here is my latest middleware implementation: export async function middleware(request: NextRequest) { const token = request.headers.get('token') console.log(token) if (!token || token == undefined) { return NextResponse.redirect(new URL('/lo ...

Error: Failed to execute close function in inappbrowser for Ionic application

Working on integrating the "in-app-browser" plugin with my Ionic project. Check out the code snippet below: const browser = this.iab.create(mylink, '_blank'); browser.on('loadstop').subscribe( data => { if ...

tslint issues detected within a line of code in a function

I am a novice when it comes to tslint and typescript. Attempting to resolve the error: Unnecessary local variable - stackThird. Can someone guide me on how to rectify this issue? Despite research, I have not been successful in finding a solution. The err ...

The expansion feature of PrimeNG Turbotable

I'm currently facing an issue with the Primeng Turbotable where I am unable to expand all rows by default. You can find a code example of my problem at this link. I have already tried implementing the solution provided in this example, but unfortuna ...

When using veevalidate to reset a form in TypeScript, the form is not fully reset as

When I have a form with veevalidate and submit it, the data is emitted to the parent component, but I struggle with resetting the form. According to the veevalidate guidelines, the form should be reset using $refs. To set up the refs, follow this link: T ...

Develop a custom cell editor for ag-Grid and insert it into a designated location within

I am currently working with Angular 16 and AgGrid 30. My goal is to have the cell editor created in a different location than its default position, which is within a div element at the bottom of the body with these classes: ag-theme-material ag-popup. I w ...