[TypeScript语法1]quick start

来源:互联网 发布:淘宝小二网站 编辑:程序博客网 时间:2024/06/05 08:40

由于公司需要,暂时先放下es6的学习,先重点看typescript,回头再看es6。

/**练习typeScript-1 * Created by liyanq on 17/6/7. *//*1,函数参数写成person: string这样,编译成es5后,直接把string拿掉了,根本不鸟~ * 2,interface的声明编译成es5后,直接被忽略~ * 3,接口声明了字段后,对象必须实现,否则不匹配~ * 4,constructor函数中,public修饰的参数,直接会增加一个public字段*/interface Person {    FirstName: string;    LastName: string;    thirdName: string;}function greeter(person: Person) {    return "Hello " + person.FirstName + ' ' + person.LastName + " " + person.thirdName;}// var user = [1,2,3];Argument of type 'number[]' is not assignable to parameter of type 'string'var user = {FirstName: "Jane", LastName: "User", thirdName: "twelveMan"};console.log(greeter(user));class Student {    private fullName: string;    constructor(FirstName: string, public thirdName, public LastName) {        this.fullName = FirstName + " " + thirdName + " " + LastName;    }}var s = new Student("Jane", ".M", "user");console.log(s);//Student { thirdName: '.M', LastName: 'user', fullName: 'Jane .M user' }let [a,b,c]=[1, 2, 3];console.log(a, b, c);//1 2 3


原创粉丝点击