Skip to main content
ProductsDesktop toolsTASTECADDrawing reviewTASTEFILESFile managementTASTEFTPFile transferTASTESSHRemote workspaceTASTEZIPCompression and extractionTASTEWINMFile managementDeveloper toolsTASTECODERust integrated development environmentTASTESTUDIOIntegrated development and test environmentTASTEETLData integration (ETL)ServersTASTEREMOTERemote desktop serverTASTEGEOGeospatial serverTASTEMAILMail workspaceInvestingTASTESTOCKStock auto-trading desktop appGet startedDownloadsDocumentationBuyAll products
Marketplace
News
TechNewsToday's dev newsDeveloper docsProgramming languagesRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWeb front-end frameworksNext.jsReactVue.js · NuxtSvelteKitAngularServer frameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressApp & desktop frameworksTauriFlutterReact NativeElectronAlgorithmsAlgorithm basicsCore algorithmsAdvanced algorithmsPractical algorithms
CommunityProjectsDevelopment logsPromptsAI tool issuesShowcaseCommunity guide
Work with usTech transferWebsite buildDesktop app buildRelease and payment pipelineSales partnerContact
ServicesRemote desktopCustom installer packages
TASTEDEV
Products

Desktop tools

TASTECADComplex drawings, opened with easeTASTEFILESJust the files you need, as fast as possibleTASTEFTPThe tidiest path for your filesTASTESSHA stronger link between you and your serversTASTEZIPPack faster, unpack saferTASTEWINMA keyboard-first file manager with two panes

Developer tools

TASTECODEEdit, build, debug and test Rust apps in one windowTASTESTUDIOFrom editing to remote tests and approved AI fixesTASTEETLMove data while you watch the values

Servers

TASTEREMOTEA remote desktop you run on your own serverTASTEGEORebuilding a GeoServer-compatible geospatial server in RustTASTEMAILTake back control of your email

Investing

TASTESTOCKStock auto-trading that follows the rules you set: when, and what

Get started

DownloadsLatest builds of every productDocsHow to use each productBuySubscriptions and perpetual licencesAll productsEvery product at a glance
All products
MarketplaceNews
Tech

News

Today's dev newsOfficial announcements on languages, frameworks, GitHub and AIDeveloper docsGuides to languages, frameworks and algorithms

Programming languages

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Frameworks

Web front-end frameworksNext.jsReactVue.js · NuxtSvelteKitAngular
Server frameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
App & desktop frameworksTauriFlutterReact NativeElectron

Algorithms

Algorithm basicsComplexity analysis · Sorting · Searching · Basic data structures · Trees and heapsCore algorithmsGraph traversal · Shortest paths & minimum spanning trees · Dynamic programming · Greedy algorithms · Divide and conquer · BacktrackingAdvanced algorithmsString algorithms · Math and number theory · Bit manipulation · Segment trees · Union-findPractical algorithmsCoding interview strategy · LRU cache · Rate limiting · Consistent hashing
All development docs
Community
ProjectsDiscover builders and their workDevelopment logsDecisions and lessons learnedPromptsReusable instructionsAI tool issuesProblems and workarounds for Claude, Codex, GeminiShowcaseFinished resultsCommunity guideHow we build in the open
Work with us
Tech transferNative apps in Rust and eguiWebsite build10 languages, accounts, docs and downloadsDesktop app buildRust and egui, no WebViewRelease and payment pipelineSigning, MSI, deb, rpm, AppImage, hashesSales partnerRecommend us and earn 30%ContactBuilds, partnerships and investment
Services
Remote desktopReach your computer from a browserCustom installer packagesOnly the features you need, settings preloaded
Buy
EN
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Log in
Log in
TASTEDEV

From small tools to better development.

support@tastedev.netSupport TASTEDEV
ProductsProduct lineupBuyDocsDownloadsMarketplaceSupport
CommunityProjectsDevelopment logsPromptsAI tool issuesShowcase
PoliciesAbout usPrivacy policyTerms of serviceSubscription termsRefund policyCommunity guidelines
AccountLog inSign up
Visitors
Today
Yesterday
Total views
Company
GXSOFT
Representative
CHOI YOUNG GU
Business registration number
853-44-00368
Address
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Phone
+82-10-4404-1523
Email
whitecalvin@tastedev.net
Privacy officer
CHOI YOUNG GU

© 2026 TASTEDEVProduct information is based on verified development sources.Released · improving

TypeScript docs
TypeScript
Getting StartedSyntax BasicsTypes and DataModules and PackagesErrors and TestingKey Concepts: The Type System
Discussions

TypeScript guide · 2/6

Syntax Basics

TypeScript's syntax is JavaScript's syntax. What it adds is a way to describe the types of variables, parameters, and return values. This chapter covers declarations, functions, arrow functions, and control flow, along with a practical rule of thumb for when to write types yourself and when to let the compiler infer them.

let and const

Declare variables with let or const. A const binding cannot be reassigned; a let binding can. Both are block-scoped, meaning they only exist inside the nearest pair of braces. The legacy var keyword is function-scoped and full of surprises, so leave it out of new code.

const appName = "TASTEDEV";   // cannot be reassigned
let count = 0;                // can change
count += 1;

const user = { name: "Kim", age: 30 };
user.age = 31;                // fine: properties are still mutable
// user = { name: "Lee", age: 20 }; // error: cannot assign to a const

if (count > 0) {
  const inner = "only visible inside this block";
  console.log(inner);
}

Note that const locks the binding, not the object it points to. A good default is to reach for const everywhere and switch to let only when a value genuinely needs to change. Readers then know at a glance which names can move.

Annotations and inference

Writing : Type after a name is a type annotation. Most of the time you can skip it, because TypeScript infers the type from the initial value.

let title: string = "Guide"; // annotated, but redundant
let pages = 120;              // inferred as number
const lang = "en";            // inferred as the literal type "en"

let total: number;            // no initializer, so annotate
total = pages * 2;

// pages = "many"; // error: string is not assignable to number

Because pages is a let, it gets the wide type number. lang is a const that can never change, so its type is the exact value "en". That is called a literal type, and it becomes important in chapters 3 and 6.

Places where an explicit annotation pays off:

  • Function parameters. There is nothing to infer from, so always annotate them.
  • Return types of exported functions. They act as a contract and stop accidental changes.
  • Variables declared without a value, and empty arrays you fill in later.

Functions

Annotate each parameter, and optionally the return type after the parameter list. Mark a parameter optional with ?, or give it a default value.

function add(a: number, b: number): number {
  return a + b;
}

function formatName(first: string, last?: string): string {
  return last ? `${first} ${last}` : first;
}

function repeat(text: string, times = 2): string {
  return text.repeat(times); // times is inferred as number
}

function sum(...values: number[]): number {
  return values.reduce((acc, v) => acc + v, 0);
}

function log(message: string): void {
  console.log(message); // no return value, so void
}

add(1, 2);           // 3
formatName("Ada");   // "Ada"
sum(1, 2, 3, 4);     // 10

Unlike plain JavaScript, TypeScript checks the number of arguments too. Calling add(1) is an error; if a parameter may be omitted, say so with ? or a default.

Arrow functions

Arrow functions are compact and do not bind their own this, which makes them ideal for callbacks. When you pass an arrow function as a callback, its parameter types are inferred from context, so you rarely need to annotate them.

const square = (n: number): number => n * n;

const toUpper = (s: string) => s.toUpperCase(); // return type inferred

const scores = [72, 95, 88];
const passed = scores.filter((score) => score >= 80); // score: number
const labels = scores.map((score, index) => `#${index + 1}: ${score}`);

type Comparator = (a: number, b: number) => number;
const ascending: Comparator = (a, b) => a - b;
console.log([...scores].sort(ascending));

Naming a function shape, as Comparator does here, lets you reuse the same signature across many functions.

Control flow

Conditionals and loops work exactly as in JavaScript. Use === and !== for comparisons; they never coerce types behind your back.

function grade(score: number): string {
  if (score >= 90) {
    return "A";
  } else if (score >= 80) {
    return "B";
  }
  return "C";
}

function dayName(day: number): string {
  switch (day) {
    case 0: return "Sunday";
    case 6: return "Saturday";
    default: return "Weekday";
  }
}

const fruits = ["apple", "pear", "persimmon"];
for (const fruit of fruits) {
  console.log(fruit);            // iterates over values
}
for (let i = 0; i < fruits.length; i++) {
  console.log(i, fruits[i]);
}

let n = 3;
while (n > 0) {
  n--;
}

const status = n === 0 ? "done" : "running";

For arrays, for...of is the most readable loop. Avoid for...in on arrays: it walks over keys as strings, not values.

Summary

  • Default to const, use let when a value must change, and skip var.
  • Let inference handle initialized variables; annotate parameters and exported return types.
  • Express optional parameters with ?, defaults with =, and rest parameters with ....
  • Callback parameters in arrow functions pick up their types from context.
  • Compare with ===, and loop over arrays with for...of.
Questions about this chapter?
Previous chapterGetting StartedNext chapterTypes and Data

0 comments

Top commentsNewest first

Sign in · Sign in to leave a comment.