A simple TypeScript starter project for learning and experimentation.
- Clone or download this project
- Install dependencies:
npm install- Run the project:
npm run devYou should see colored output showing the test results!
my-ts-project/
├── src/
│ ├── index.ts # Main entry point
│ └── test1.ts # Example test module
├── dist/ # Compiled JavaScript (generated)
├── .vscode/ # VS Code configuration
│ ├── launch.json # Debug configurations
│ ├── tasks.json # Build tasks
│ ├── settings.json # Project settings
│ ├── extensions.json # Recommended extensions
│ └── typescript.code-snippets # Custom code snippets
├── eslint.config.js # ESLint configuration
├── .prettierrc # Prettier configuration
├── package.json # Project dependencies and scripts
└── tsconfig.json # TypeScript compiler options
The project is organized around simple test modules that you can experiment with:
test1.ts- Basic TypeScript examples (classes, async, fetch)test2.ts- ESLint & SonarJS code smell demonstrationstest3.ts- Calculator class with GitHub Copilot demotest3.test.ts- Test suite for Calculator classindex.ts- Imports and runs all test modules
- Create a new file:
src/test2.ts - Export a
runTest()function:export function runTest(): void { console.log("Running test 2..."); // Your code here }
- Import it in
index.ts:import { runTest as runTest2 } from "./test2.js";
- Call it:
runTest2();
- Run with
npm run dev
You can create test2.ts, test3.ts, test4.ts, etc. and experiment freely!
Notice the .js extension in imports:
import { runTest } from "./test1.js"; // .js, not .ts!This is correct! When using ES Modules in TypeScript:
- You write code in
.tsfiles - TypeScript compiles them to
.jsfiles indist/ - Import statements are not changed by the compiler
- So you must use
.jsextensions even though the source files are.ts
This is a TypeScript quirk with ES modules that often confuses beginners.
npm run build # Compile TypeScript to JavaScript
npm run watch # Watch mode - auto-recompile on changes
npm start # Run the compiled program
npm run dev # Build and run in one commandnpm test # Compile and run tests with Node.js test runnernpm run lint # Check code with ESLint
npm run lint:fix # Auto-fix ESLint issues
npm run format # Format code with PrettierThe easiest way to run the project:
npm run dev- F5 - Start debugging (with breakpoints)
- Ctrl+F5 - Run without debugging
- Or use the Run menu and select "Debug Program"
- Open a
.tsfile insrc/ - Click in the left margin to add a red breakpoint
- Press F5 to start debugging
- Execution will pause at your breakpoint
This project includes useful shortcuts to speed up your coding:
ts_log→console.log();ts_logl→console.log('label:', variable);ts_fn→ Create a functionts_af→ Create an arrow functionts_expfn→ Export a functionts_int→ Create an interfacets_type→ Create a typets_for→ Simple for loop
Just type ts_ and you'll see all available snippets! Press Tab or Enter to use them.
When you open this project, VS Code will suggest installing:
- ESLint - Code quality and style checking (catches unused variables,
anytypes, etc.) - Prettier - Automatic code formatting
- TypeScript Next - Latest TypeScript features
- Error Lens - Inline error messages (very helpful!)
You can install them by clicking the notification or opening the Extensions panel (Ctrl+Shift+X).
This project is configured to help you write better code automatically:
- Format on Save - Your code is automatically formatted when you save
- ESLint Auto-Fix - Many issues are fixed automatically on save
- Inline Warnings - Error Lens shows problems directly in your code
- SonarJS - Code smell detection (duplicate code, complexity, etc.)
Test 2 demonstrerer ESLint og SonarJS code smell detection!
I src/test2.ts finder du eksempler på code smells (kommenteret ud):
- 🔴 Duplicate strings - Samme tekst gentaget mange gange
- 🔴 Cognitive complexity - For mange nested if-statements
- 🔴 Identical functions - To funktioner med samme kode
- 🔴 Duplicate conditions - Samme betingelse i if-else
Prøv det selv:
- Åbn
src/test2.ts - Uncomment de kommenterede code smells
- Kør
npm run lintfor at se warnings - Læs fejlbeskeder og forstå hvad der er galt
- Ret fejlene for at lære best practices
Dette lærer dig at skrive renere og mere vedligeholdelig kode!
- F5 - Start debugging
- Ctrl+F5 - Run without debugging
- Ctrl+Shift+B - Build (compile TypeScript)
- Ctrl+` - Toggle terminal
- Ctrl+P - Quick file open
- F12 - Go to definition
- Alt+Shift+F - Format document
- Ctrl+Space - Trigger autocomplete
Test 3 demonstrerer hvordan GitHub Copilot kan hjælpe dig med at skrive kode!
I src/test3.ts finder du en Calculator klasse:
- ✅
add()metoden er færdig og virker - ❌
subtract()metoden mangler implementation (smider en fejl)
- Åbn
src/test3.ts - Find
subtract()metoden (linje ~59) - Slet linjen
throw new Error("Not implemented yet..."); - Skriv
returnog vent på Copilot's forslag (grå tekst) - Tryk Tab for at acceptere forslaget
- Gem filen og kør
npm testfor at verificere
Forventet Copilot-forslag:
return _a - _b;Filen indeholder to prompts i kommentarer til brug med AI agents eller Copilot:
PROMPT 1: Fix Implementation
- Implementer manglende metoder
- Kør tests og ret fejl
- Fix alle lint warnings
- Bliv ved indtil alt er grønt
PROMPT 2: Add Missing Methods
- Tilføj nye metoder (multiply, divide, power, squareRoot)
- Skriv tests for hver metode
- Håndter edge cases (division med 0, negative tal)
- Verificer med tests og lint
Disse prompts guider AI til at arbejde systematisk gennem opgaver.
Projektet inkluderer tests i src/test3.test.ts:
- ✅ 3 tests for
add()(passerer) - ❌ 3 tests for
subtract()(fejler indtil du implementerer metoden)
Kør tests:
npm test # Se testresultater
npm run dev # Kør demo i konsollen
npm run lint # Verificer kode kvalitetCopilot lærer fra:
- Eksisterende kode -
add()metoden viser mønstret - Kommentarer - Danske kommentarer forklarer hvad koden skal gøre
- Tests - Test cases viser forventet funktionalitet
- Kontekst - Klasse navn, metode navne, parameter typer
Dette gør Copilot i stand til at foreslå korrekt implementation!
This starter kit demonstrates:
- ✅ TypeScript compilation with strict mode enabled
- ✅ ES Modules (modern import/export syntax)
- ✅ Async/await - Modern asynchronous JavaScript with fetch example
- ✅ Node.js test runner - Built-in testing (no external dependencies)
- ✅ Test-Driven Development - Write tests, implement code, verify
- ✅ GitHub Copilot demo - Learn how AI can assist your coding
- ✅ AI Agent prompts - Built-in prompts for automated development
- ✅ SonarJS - Code smell detection and quality analysis
- ✅ Source maps for debugging
- ✅ ESLint - Code quality and linting
- ✅ Prettier - Automatic code formatting
- ✅ NPM package usage (chalk for colored console output)
- ✅ Module system with test files
- ✅ VS Code integration with debugging support
- ✅ Custom code snippets for faster development
- ✅ Format on save and auto-fix on save
- TypeScript Handbook
- TypeScript for JavaScript Programmers
- VS Code TypeScript Tutorial
- Node.js Test Runner Documentation
- GitHub Copilot Documentation
- SonarJS Rules
The project uses strict TypeScript settings for best practices:
strict: true- All strict type-checking options enablednoUncheckedIndexedAccess: true- Safer array/object accessexactOptionalPropertyTypes: true- Stricter optional properties- Source maps and declaration files enabled