function add(a: number, b: number): number { return a + b; } const result = add(1, 2); console.log(result); // const wrongResult = add(1, "2"); // TypeScript 会在写代码阶段直接提示: // 第二个参数应该是 number,但这里传入了 string。