Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Core Tech
Labs

Guided: Implement Interfaces, Enums, and Type Guards in TypeScript - Geometry Helper Part 2

This lab is the second in a 2-part series wherein you will be building a geometry helper library using Typescript. In this part, you will be using enums, interfaces, and type guards to implement functions and types that are needed to support 2D points. Once implemented, you will continue to utilize exports and imports for your library to be used in the example application.

Lab platform
Lab Info
Level
Beginner
Last updated
Aug 29, 2025
Duration
53m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Introduction

    Welcome to Guided: Implement Interfaces, Enums, and Type Guards in TypeScript - Geometry Helper Part 2. This is the second lab in a two-lab series in which you will be implementing a library for performing geometric calculations using Typescript.

    In this part of the series, you will be using structures such as enums, interfaces, and type guards to implement calculations involving 2D points.

    Finally, you will be exporting and importing your library to be used within the main application. If you are stuck at any time, feel free to take a look at the solution directory.

    The application will throw errors when run until you complete the lab. Once completed, it should work correctly.

    How to Run the App:

    The application can be started by clicking the Run button in the Terminal or by running the command npm start in the Terminal.

  2. Challenge

    Step 1: Implementing Types

    First, you will need to define a few structures for handling the calculations between 2D points.

    A LineType enum, or set of constant values, is useful here for determining the type of the line formed between two points. A Point interface is necessary here to specify the structure of a 2D point. In this case, it will just be an object with x and y properties as numbers.

    Finally, a type guard is useful to verify that a specified object correctly implements the Point interface. In other words, it will verify that an object is indeed a Point. This will be necessary for validating inputs in the main app.ts file.

  3. Challenge

    Step 2: Implementing Point Calculations

    Now that you've defined LineType, Point, and the isPoint type guard, you'll now need to implement functions for 2D point calculations. These include slope, distance, midpoint, and the equation of a line passing through two given points.

    All of these functions will take two Point parameters, which allow any object that implements the Point interface. They will then return a string or number by calculating the specified value using the x and y coordinates of the two given Point parameters.

  4. Challenge

    Step 3: Exporting and Importing

    Finally, you'll need to import your types and calculation functions into index.ts and re-export them for use in app.ts just like you did in part 1 of this lab.

    This time, you'll have many more types and functions prefaced with the export keyword in their individual files. This can make importing in index fairly verbose, so instead you can just import the file in index with a statement such as import filepath.

    Re-exporting everything from this import typically follows the syntax export * from filepath. All done! You can now run the application by clicking the Run button in the Terminal.

    When executed, the application will prompt you for the calculations you'd like to perform (including the shapes from part 1) before asking you to input your desired values.

    Once entered, it will display the results from the calculations using the functions you implemented!

About the author

George is a Pluralsight Author working on content for Hands-On Experiences. He is experienced in the Python, JavaScript, Java, and most recently Rust domains.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight