1. Home
  2. /
  3. TypeScript
  4. /
  5. Drag and Drop Example

Drag and Drop Example - TypeScript Typing CST Test

Loading…

Drag and Drop Example — TypeScript Code

Enables dragging and dropping of elements with proper TypeScript types.

document.addEventListener('DOMContentLoaded', () => {
	const draggable = document.getElementById('drag') as HTMLElement;
	const dropzone = document.getElementById('drop') as HTMLElement;
	draggable.addEventListener('dragstart', (e) => { e.dataTransfer?.setData('text', 'dragged'); });
	dropzone.addEventListener('dragover', (e) => e.preventDefault());
	dropzone.addEventListener('drop', (e) => { e.preventDefault(); dropzone.textContent = 'Dropped!'; });
});

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.

More TypeScript Typing Exercises

TypeScript Theme Toggle and CounterTypeScript Form ValidationTypeScript To-Do ListTypeScript Modal ExampleTypeScript Fetch API ExampleTypeScript Tabs NavigationTypeScript Image SliderTypeScript Countdown TimerTypeScript Modal with Async Data

Practice Other Languages

CReactPythonC++RustKotlinPHPJavaC#RubyMqlCqlN1qlCypherGremlin