Day|Day 1/100 自动执行TypeScript和interface、type 区别
前言
1、适合新手入门;1、如何自动执行ts文件?
2、眼过千遍,不如手过一遍,看文档,我忘记了很多次;建议大家边看边运行Demo。
3、官网在线运行地址: https://www.typescriptlang.or...
使用ts-node直接运行TypeScript代码
npm install -g ts-node
ts-node demo1.ts
2、函数的类型
【Day|Day 1/100 自动执行TypeScript和interface、type 区别】即函数的返回值类型
function sanitizeInput(str: string): string {
return str + ',arden';
}
console.log(sanitizeInput('hi'));
3、Interface和type的共同点和区别
1)共同点 都可以声明类型
interface Point {
x: number;
y: number;
}//type Point {
//x: number;
//y: number;
//}function printCoord(pt: Point) {
console.log("The coordinate's x value is " + pt.x);
console.log("The coordinate's y value is " + pt.y);
}printCoord({ x: 100, y: 200 });
2)不同点
类型 | 拓展方式 | 表列 B |
---|---|---|
interface | 通过extends 父类型拓展 | 可以向现有类型添加新字段 |
type | 通过 父类型 &{} 拓展 | 不可以向现有界面添加新字段 |
推荐阅读
- 赢在人生六项精进二阶Day3复盘
- 继续努力,自主学习家庭Day135(20181015)
- python学习之|python学习之 实现QQ自动发送消息
- 2019-01-17-晨读7期-直子Day25
- 21天|21天|M&M《见识》04
- 使用composer自动加载类文件
- 阿菘的ScalersTalk第五轮新概念朗读持续力训练Day15|阿菘的ScalersTalk第五轮新概念朗读持续力训练Day15 20191025
- 桂妃研读社|桂妃研读社|D124|如何有效阅读一本书 Day1
- 人脸识别|【人脸识别系列】| 实现自动化妆
- 【70号】Day26朋友日