01.ts 306 B

123456789101112131415161718192021
  1. let a: number;
  2. a = 4;
  3. function sum(a: number,b: number): number{
  4. return a + b;
  5. }
  6. let x: number = 1;
  7. let y = false;
  8. // &表示同时
  9. let j: {name: string} & {age: number};
  10. j = {name: 'ddd',age: 33};
  11. let n: number | boolean;
  12. // 类型别名
  13. let k: 1 | 2 | 3;
  14. type myType = 1 | 2 | 3;
  15. let m: myType;