一、声明一个参数的函数

参数必须指定类型

1-1、string型

  1. function fun(s:string):string{
  2. console.log(s)
  3. return s
  4. }
  5. fun("hello") // 输出 hello
  6. function fun(s:string="hello world"):string{
  7. console.log(s)
  8. return s
  9. }
  10. fun("good") // 输出 good (覆盖)

1-2、any 型

  1. function fun(s:any):any{
  2. console.log(s)
  3. return s
  4. }
  5. fun("hello")