年払い 年払いなら、すべての有料プランで2か月分が無料。 プランを見る
サインイン 無料で始める

コード翻訳

入力
コード
function add(a, b) { return a + b; }
サンプル出力 27 10月 2026に作成

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

Notes:

  • The TypeScript version explicitly accepts and returns number.
  • Unlike the JavaScript original, calls with strings or other non-number values are rejected at compile time.
  • TypeScript types are erased at runtime, so JavaScript callers can still pass incompatible values unless runtime validation is added.
  • number includes floating-point values, NaN, and Infinity.
  • JavaScript’s usual numeric behavior still applies, including floating-point precision issues and coercion at runtime.
これを使う コード翻訳 フォームはこのサンプルの入力が入った状態で開きます。自由に変更できます。