Skip to content

TanjaSav/M3G8-DataTypes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contact List Using TypeScript

Project Description

This is a web-based script written in TypeScript that demonstrates how to work with various data types, particularly with an array of contact objects. It includes:

  • Creating and displaying contact information
  • Adding, modifying, and deleting object properties
  • Performing arithmetic operations
  • Using Math.random() to generate a random contact
  • Displaying the current date and time
  • Rendering all output directly to the web page using the DOM: each message is added as a new <p> element inside the #contact-container.

Use of Strict Mode "use strict"

TypeScript automatically enables strict mode during compilation if the following is set in tsconfig.json:

{  
  "compilerOptions": {  
    "target": "ES6",  
    "strict": true  
  }  
}
  • "strict": true enables a suite of strict type-checking options, including alwaysStrict
  • The compiled main.js file will automatically include "use strict" at the top
  • This ensures safer execution and prevents common JavaScript pitfalls.

Project Structure


├── index.html          // Main HTML entry point  
├── main.ts             // TypeScript logic  
├── main.js             // Compiled JavaScript output  
├── tsconfig.json       // TypeScript configuration  
├── package.json        // Project metadata and dependencies  
├── package-lock.json   // Locked versions of installed packages  
├── node_modules/       // Installed libraries  
└── README.md           // Project documentation

How to Run

  1. Initialize the project:
 npm init -y
  1. Install TypeScript:
 npm install typescript --save-dev
  1. Create TypeScript configuration file:
 npx tsc --init
  1. Generates a tsconfig.json file to configure the TypeScript compiler. Example configuration:
{
  "compilerOptions": {
    "target": "ES6",
    "module": "commonjs",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "strict": true,
    "skipLibCheck": true
  }
}
  1. Create a new main.ts file and write your logic inside.
 main.ts
  1. Сompile main.ts to generate main.js file:
 npx tsc main.ts
  1. Compile TypeScript to JavaScript:
 npx tsc
  1. Create a new index.html file and link the compiled script:
index.html
<script src="main.js" type="module"></script>
  1. Open index.html in your browser using Live Server to see the output results

Output Link

This is the link to the output results: https://tanjasav.github.io/M3G8-DataTypes/

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published