美文网首页
2018年6月8日 TypeScript 培训

2018年6月8日 TypeScript 培训

作者: zing_3c94 | 来源:发表于2018-06-06 16:44 被阅读0次

    初始Typescript

    ## TypeScript 的培训课程的介绍

        react与typeScript环境搭建TypeScript的基本语法介绍

    ## TypeScript 的介绍

        TypeScript 扩展了JavaScript语法,任何已经存在的JavaScript程序,可以不加任何改动,在TypeScript环境下运行。TypeScript只是向JavaScript添加了一些新的遵循ES6规范的语法,以及基于类的面向对象编程的这种特性。

    微软开发的一门编程语言

    JavaScript的超集

    遵循最新的ES6规范

    ## TypeScript 的优势

    1.支持ES6规范

    2.强大的IDE(Integrated Development Environment 集成开发环境)的支持

    (1)类型检查   指出类型错误

    (2)语法提示   根据上下文,提示代码

    (3)重构   对变量等等进行修改时,会对其它地方的相同变量等进行相应修改

    3. Angular2的开发语言

    ## 基于react 搭建TypeScript开发环境配置

      1.在线编译  http://www.typescriptlang.org/play/index.html

        

      2.本地环境配置:     

                (1)执行命令:npm install -g create-react-app 

                                            create-react-app my-app --scripts-version=react-scripts-ts

                (2)dva+react +antd

                (3)https://www.runoob.com/w3cnote/getting-started-with-typescript.html

     3.ts.config.js配置文件地址中文翻译:

        官方英文版:http://json.schemastore.org/tsconfig

        https://zhongsp.gitbooks.io/typescript-handbook/content/doc/handbook/Compiler%20Options.html    

    ## 基础类型申明

      1.几种基本类型

                boolean  number string(包括模版字符串) Array[] (Array<元素类型>  ,元组 Tuple )  enum  

                Any (任何类型) Void (无返回值)  Null 和 Undefined  Never 类型断言

      2.字符串的新特性

              2-1 字符串模板 

              2-2  自动拆分字符串

      3.参数新特性:

     (1)定义:在参数名称后面添加参数类型  例如:var myname: string = 'yangfan';

     (2)变量推断机制: 当声明变量时,没有添加变量类型。当重新赋值时,会默认其对象类型为第一次赋值的类型;

     (3)函数的参数类型;function test(name: string): string

     (4)参数默认值:function test(a: string, b: number, c: Boolean = false)

     (5)可选参数:function test(a: string, b?: number, c: Boolean = false) 

    ## 接口

    以下是接口的几种常见形式:

    // 定义具有 color 和 width 属性的对象

    interface SuperConfug {

      color: string;

      width: number;

    }

    // readonly 表示只读,不能对其属性进行重新赋值

    interface Point {

      readonly x: number;

      readonly y: number;

    }

    // ?表示属性是可选的,

    // [propName: string]: any 表示允许 obj[xxx] 这样的动态属性

    interface SquareConfig {

      color?: string;

      width?: number;

      [propName: string]: any;

    }

    // 函数接口

    interface SearchFunc {

      (source: string, subString: string): boolean;

    }

    ##类

        定义:类是对现实生活中一类具有共同特征的事物的抽象

        1.public

        2.private

        3.protected

        4.继承 (派生类)

    ## 泛型

        没什么特别的 其实就是可以看成一个数组 然后里面指定了数据类型;

        

        



            

    相关文章

      网友评论

          本文标题:2018年6月8日 TypeScript 培训

          本文链接:https://www.haomeiwen.com/subject/fuabsftx.html