本文へスキップ
製品デスクトップツールTASTECAD図面の確認TASTEFILESファイル管理TASTEFTPファイル転送TASTESSHリモートワークスペースTASTEZIP圧縮と展開TASTEWINMファイル管理開発ツールTASTECODERust 統合開発環境TASTESTUDIO統合開発・テスト環境TASTEETLデータ統合(ETL)サーバーTASTEREMOTEリモートデスクトップサーバーTASTEGEO空間情報サーバーTASTEMAILメールワークスペース投資TASTESTOCK株式自動売買デスクトップアプリはじめるダウンロードドキュメント購入すべての製品
マーケットプレイス
ニュース
技術ニュース今日の開発ニュース開発ドキュメントプログラミング言語RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWebフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngularサーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Expressアプリ・デスクトップ フレームワークTauriFlutterReact NativeElectronアルゴリズムアルゴリズムの基礎主要アルゴリズム発展アルゴリズム実務のアルゴリズム
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケースコミュニティガイド
協業技術移転ウェブサイト構築デスクトップアプリ構築リリース・決済パイプライン販売パートナーお問い合わせ
サービスリモートデスクトップインストールパッケージのカスタマイズ
TASTEDEV
製品

デスクトップツール

TASTECAD複雑な図面を、軽やかにひらくTASTEFILES必要なファイルだけを、最速でTASTEFTPファイルが行き交う、いちばん端正な道TASTESSHサーバーとあなたを、より確かにつなぐTASTEZIPより速くまとめ、より安全にひらくTASTEWINM2つの画面で整理する、キーボード中心のファイルマネージャー

開発ツール

TASTECODERust アプリの編集・ビルド・デバッグ・テストまでひとつのウィンドウでTASTESTUDIO編集からリモートテスト、承認した AI 修正までTASTEETL値を見ながら、データを運ぶ

サーバー

TASTEREMOTE自社サーバーで運用するリモートデスクトップTASTEGEOGeoServer 互換の空間情報サーバーを Rust で作り直しますTASTEMAILメールの主導権を、もう一度自分の手に

投資

TASTESTOCKいつ・何を。自分で決めたルールどおりに動く株式自動売買

はじめる

ダウンロード全製品の最新版ドキュメント各製品の使い方購入サブスクリプション・永久ライセンスすべての製品全製品を一覧で
すべての製品
マーケットプレイスニュース
技術

ニュース

今日の開発ニュース言語・フレームワーク・GitHub・AI の公式発表開発ドキュメント言語・フレームワーク・アルゴリズムのガイド

プログラミング言語

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

フレームワーク

Webフロントエンド フレームワークNext.jsReactVue.js · NuxtSvelteKitAngular
サーバー フレームワークSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
アプリ・デスクトップ フレームワークTauriFlutterReact NativeElectron

アルゴリズム

アルゴリズムの基礎計算量解析 · ソート · 探索 · 基本データ構造 · 木構造とヒープ主要アルゴリズムグラフ探索 · 最短経路と最小全域木 · 動的計画法 · 貪欲法 · 分割統治法 · バックトラッキング発展アルゴリズム文字列アルゴリズム · 数学と整数論 · ビット演算 · セグメント木 · Union-Find実務のアルゴリズムコーディング面接対策 · LRUキャッシュ · レート制限 · コンシステントハッシュ法
開発ドキュメントをすべて見る
コミュニティ
プロジェクトビルダーと作品を探す開発ログ決定と試行錯誤プロンプト再利用できる指示AIツールの問題Claude・Codex・Gemini の問題と回避策ショーケース完成した成果コミュニティガイドオープンにつくる方法
協業
技術移転Rust・egui でネイティブアプリを作るウェブサイト構築10言語、アカウント、ドキュメントとダウンロードデスクトップアプリ構築Rust・egui、WebView なしリリース・決済パイプライン署名・MSI・deb・rpm・AppImage・ハッシュ販売パートナー紹介して決済額の30%お問い合わせ構築・提携・投資のご相談
サービス
リモートデスクトップブラウザから自分のパソコンへインストールパッケージのカスタマイズ必要な機能だけ、設定は事前に
購入
JA
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
ログイン
ログイン
TASTEDEV

小さなツールから、より良い開発へ。

support@tastedev.netTASTEDEVを支援
製品製品ラインナップ購入ドキュメントダウンロードマーケットプレイスサポート
コミュニティプロジェクト開発ログプロンプトAIツールの問題ショーケース
ポリシー会社概要プライバシーポリシー利用規約サブスクリプション規約返金ポリシーコミュニティガイドライン
アカウントログイン新規登録
訪問者
今日
昨日
累計閲覧
商号
GXSOFT
代表者
CHOI YOUNG GU
事業者登録番号
853-44-00368
所在地
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
電話
+82-10-4404-1523
メール
whitecalvin@tastedev.net
個人情報保護責任者
CHOI YOUNG GU

© 2026 TASTEDEV製品情報は検証済みの開発ソースに基づいています。リリース・改善中

TypeScript ドキュメント
TypeScript
Getting StartedSyntax BasicsTypes and DataModules and PackagesErrors and TestingKey Concepts: The Type System
ディスカッション

TypeScript ガイド · 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
この章について質問がありますか?
前の章Getting Started次の章Types and Data

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.

コメント 0件

人気のコメント順新しい順

ログイン · ログインするとコメントできます。