Image Slider - TypeScript Typing CST Test
Loading…
Image Slider — TypeScript Code
Creates a simple image slider with next/previous buttons.
document.addEventListener('DOMContentLoaded', () => {
const images = document.querySelectorAll('.slide') as NodeListOf<HTMLImageElement>;
let index = 0;
const nextBtn = document.getElementById('next') as HTMLButtonElement;
const prevBtn = document.getElementById('prev') as HTMLButtonElement;
function show(i: number) {
images.forEach(img => img.style.display = 'none');
images[i].style.display = 'block';
}
nextBtn.addEventListener('click', () => { index = (index + 1) % images.length; show(index); });
prevBtn.addEventListener('click', () => { index = (index - 1 + images.length) % images.length; show(index); });
show(index);
});TypeScript Language Guide
TypeScript is a statically typed superset of JavaScript that enhances developer productivity, scalability, and reliability by adding static types, modern tooling, and advanced language features while compiling to plain JavaScript for any runtime.
Primary Use Cases
- ▸Large-scale frontend development
- ▸Backend APIs with Node.js, Deno, or Bun
- ▸Cross-platform mobile apps with React Native
- ▸Cloud functions and serverless workloads
- ▸Library and SDK development
- ▸Type-safe dev tooling and automation scripts
Notable Features
- ▸Static typing with strong type inference
- ▸Interfaces, generics, and advanced type system
- ▸Decorators and metadata reflection
- ▸Namespaces and ES module support
- ▸Union, intersection, and mapped types
- ▸Excellent tooling via VS Code
Origin & Creator
Created by Microsoft under the leadership of Anders Hejlsberg (creator of C#), first released publicly in 2012. Initially invented to solve JavaScript scalability issues in large applications. Evolved through major versions adding classes, modules, generics, decorators, async/await support, strict mode, union types, mapped types, and powerful type inference.
Industrial Note
TypeScript dominates enterprise-scale frontend engineering, powering frameworks like Angular, Next.js, React, Vue, Bun, Deno, and many internal developer tools at companies such as Microsoft, Google, Airbnb, Shopify, Stripe, and Meta.