Yearly Pay yearly and get 2 months free on every paid plan. See plans
登入 免費開始

程式碼轉譯

輸入
程式碼
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.
使用這個 程式碼轉譯 表單會預填此範例的輸入,可隨意修改。