# TS **Repository Path**: toddchina/ts ## Basic Information - **Project Name**: TS - **Description**: ts学习仓库 - **Primary Language**: TypeScript - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2023-05-15 - **Last Updated**: 2023-05-16 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # TS #### 介绍 ts学习仓库--ToddChina #### 笔记 ##### 2023-5-15 ###### 1. 学习内容 1. TS的定义(01-TS的定义) 1. 构建第一个TS文件 ```ts function greeter(person){ return 'hello,'+person; } let user = 'Jean Elsa'; document.body.innerHTML = greeter(user); ``` 1. 静态类型:编写TS变量的时候需要给变量注释数据类型 2. 使用TS准备的playground[PlayGround](https://www.tslang.cn/play/index.html) 2. TS的优势(02-TS的优势) 1. 开发过程中,发现潜在问题 ```ts function tsDemo(data:{x:number,y:number}){ return Math.sqrt(data.x ** 2 + data.y ** 2); } // 如果tsDemo()内不写参数,会报错 tsDemo({x:1,y:123}); ``` 2. 更友好的编辑器自动提示 3. 配置TS基础环境 1. 使用node环境,并使用cnpm进行三方包管理,npm下载错误 2. VSCode安装一个插件Prettier-Code Formatter 3. 问题,安装后VSCode设置format on save也不能自动格式化 4. node不能直接运行ts文件 $ ~~node demo.ts~~ 5. 需要转化为js文件 ```shell $ tsc demo.ts >> demo.js ``` 6. 安装使用ts-node插件可以直接运行ts文件 ```shell $ cnpm install ts-node -g $ node demo.ts ``` 7. 注意:高版本会出现TS2584的错误 ```shell $ TS2584:Cannot find name 'console'. Do you need to change your target library? Try changing the 'lib' compiler option to include 'dom' ``` 解决方法:安装依赖包tslib ```shell $ cnpm i -g tslib @types/node ``` 4. 静态类型 * TS中,如果确定了静态类型,那么数据类型不但被确定,变量中的属性和方法也会被确定。只有这样编辑器才能给我们更好的语法提示 ##### 2023-5-16 ###### 1. 学习内容 1. git 仓库使用命令 1. git clone ...(地址) 2. git pull:使线上和线下仓库同步 3. 将线下的修改同步到线上 1. git add . 2. git commit -m '20230516' 3. git push 2. 基础类型和对象类型