Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

learn typescript in one file #7

Open
hulin32 opened this issue Mar 25, 2018 · 0 comments
Open

learn typescript in one file #7

hulin32 opened this issue Mar 25, 2018 · 0 comments

Comments

@hulin32
Copy link
Owner

hulin32 commented Mar 25, 2018

typescript 是javascript的超级,在原来的基础上引入了类型系统,让代码更加好维护,正经typescript我也还没怎么写过,但在学习中比较没有类型系统时,明显会感觉typescript在项目大后会更好的维护(还没在项目中验证),希望在今后的代码中也能将起引入。

这里我想通过创建一个类来尽量诠释其全部的概念

// 枚举
enum Gender { Female, Male };

class Human {
  // string 类型
  static component: string = '碳水化合物';
}

// 接口
interface Character {
  kindly: boolean;
}

// 继承和实现
class Female extends Human implements Character {
  gender: Gender = Gender.Female;
  kindly: boolean;
  private years: number;
  name: string;
  constructor(kindly: boolean, years: number, name: string) {
    super();
    kindly = kindly;
    years = years;
  }
  // void 表示没有返回值
  sayHi(): void {
    let sentence = `Hello, I am ${this.years} years old`; // 类型推断
    console.log(sentence);
  }
}

待补充.....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant