• 2022/04/01 TypeScript_Study_Day1


    # 2022/04/01 TypeScript_Day1

    ### 背景记录

    首先我有`java`和`go`的语言基础,然后我是一名测试,现在遇到的问题是公司使用`solidity`的`truffle`和`hardhat`框架进行开发,`solidity`这门语言是运行在以太坊虚拟机上面的,他编译出来的文件可以作为`javascript`的包引入在`javascript`当中然后使用`javascript`编写测试用例.所以这就需要我去掌握`javascript`

    由于弱类型语言在看代码的时候转型的时候搞不清楚,本着逻辑清晰的原则所以选择学习`typescript`

    同时还需要能看懂`solidity`代码的上下文构造测试场景.

    ### 环境声明

    使用的是`Mac pro 14`已经预先安装了`Node.js`的环境,所以通过`Node.js`的包管理工具进行下载即可

    **修改`Node.js`包管理工具的镜像源:**

    `npm config set registry https://registry.npmmirror.com`

    **安装`typescript`环境:**

    `npm install -g typescript`

    **查看`typescript`版本:**

    `tsc -v`

    #### `HelloWorld of TypeScript`

    `
    var message:string = "HelloWorld"
    console.log(message)
    `
    **将`.ts`文件进行编译:**

    编译后会生成一个同名的`.js`文件

    `tsc HelloWorld.ts`

    **运行`.js`文件:**

    `node HelloWorld.js`

    #### 熟悉`TypeScript`编译指令

    - 多文件编译 ---> `tsc file1.ts file2.ts ...`
    - 额外生成一个`.d.ts`扩展名文件 --->该文件是个类似声明的文件 --->`tsc helloworld.ts --declaration`
    - 删除源文件的注释 --->`tsc helloworld.ts --removeComments`
    - 生成一个`sourcemap(.map)`文件 --->一个`sourcemap`是一个存储源代码与编译代码对应位置映射的信息文件 --->`tsc helloworld.ts --sourcemap`
    - 在表达式和声明上有隐含的`any`类型时报错 --->`tsc helloworld.ts module nolmplicitAny`
    - 监视模式下运行编译器(监视输出文件,输出文件被更改时重新编译) --->`tsc helloworld.ts --watch`

    #### `TypeScript`保留的关键字

    **这里只重点拿出几个关键的:**

    1. `as`
    2. `number`
    3. `get`
    4. `moudle`
    5. `export`
    6. `any`
    7. `yield`

    #### `TypeScript`拥有的一些特点

    - 分号可选
    - 区分大小写
    - 面向对象

    ##### 什么是"对象"

    谈恋爱的就叫"对象"[doge]

    所谓对象就是用一些属性和行为描述的一组或者一类型的内容

    **示例代码:**

    声明一个动物的对象,他们有眼睛和四只脚,并切能够叫和走

    <code>
    /**
    * Declare a class which is about animal
    */
    class Animal{
    eyes: number = 2
    foot: number = 4

    // Provide some function to obtain corresponding information
    getEyesNumber(): number {
    return this.eyes
    }

    getFootNumber(): number {
    return this.foot
    }

    // Provide some function about animal
    // Shout function
    shout(object: Animal): void {
    console.log("Animal can shout!")
    }

    move(object: Animal): void {
    console.log("Animal can move")
    }
    }

    // Call the function about animal
    var animal = new Animal()

    var eyeNumver: number = animal.getEyesNumber()

    var footNumber: number = animal.getFootNumber()

    console.log(eyeNumver)
    console.log(footNumber)
    animal.shout(animal)
    animal.move(animal)
    </code>

    ##### 存在疑问

    为什么上面两个`get`方法打印的结果是`[Function]`?

  • 相关阅读:
    osgearth cache
    3ds Max导出FBX动画模型在OSG中使用
    osgExp只能将3dmax中的动画导出为路径动画osg::AnimationPath,而不能导出osgAnimation::Animation。osg播放骨骼动画应该使用FBX格式
    ExtJS前端框架EXT弹出窗口事件
    大数据学习——securecrt同时向多个tab窗口发送相同的命令
    大数据学习——yarn集群启动
    如何取SQL结果集的第一条记录
    Java比较两个数组中的元素是否相同的最简单方法
    大数据学习——hdfs集群启动
    大数据学习——hadoop安装
  • 原文地址:https://www.cnblogs.com/JunkingBoy/p/16573264.html
Copyright © 2020-2023  润新知