美文网首页我爱编程
Typescript学习笔记(一)

Typescript学习笔记(一)

作者: H_DaYan | 来源:发表于2018-06-21 22:34 被阅读0次

主要简述官网,方便查找
相关参考链接
中文官网链接: https://www.tslang.cn/docs/home.html
官网链接: http://www.typescriptlang.org/docs/home.html
TypeScript 入门教程:https://legacy.gitbook.com/book/xcatliu/typescript-tutorial/details

angular中主要会用到的属性

学习Typescript主要是为了在最新的angular中使用,所以先选择angular中常用的进行学习。

基础类型
  1. boolean: 布尔值
  2. number:数字
  3. string:字符串,支持内嵌表达式
let name : string = `Gene`;
let age: number = 12;
let sentence: string = `Hello, my name is ${name}.
I'll be ${age + 1}` years old next month.`;

/****************output****************/
Hello, my name is Gene.
I'll be 13 years old next mouth.
/**************************************/
  1. 数组:两种表达方式
//第一种:直接在元素类型后面接上[]
let list: number[] = [1, 2, 3];
//第二种:数组泛型,Array<元素类型>
let list: Array<number> = [1, 2, 3];

5. 元组
元组类型是javascript中没有的
官方解释:一个已知元素数量和类型的数组,各元素的类型不必相同
简单的说,就是一个数组,但是可以是不同的类型

let x: [string, number];
x = ['hello', 10];      //ok
x = [10, 'hello'];      //error, 须与定义的顺序相同
console.log(x[0].substr(1));    //ok
console.log(x[1].substr(1));    //error, number类型没有substr属性
//但当访问一个越界元素,会使用联合类型替代
x[3] = 'world';    //ok, 赋值给(string | number)类型
console.log(x[3].toString());    //ok,string和number都有toStirng()属性
x[6] = true;   //error, 不是(string | number)类型

未完待续

相关文章

  • Typescript

    TypeScript(TS)部分 TypeScript学习笔记

  • Typescript 学习笔记六:接口

    目录: Typescript 学习笔记一:介绍、安装、编译 Typescript 学习笔记二:数据类型 Types...

  • TypeScriptz学习笔记

    TypeScriptz学习笔记 标签(空格分隔): TypeScript 撩课学院 安装TypeScript Ty...

  • Typescript

    学习笔记 菜鸟教程 《菜鸟教程》-TypeScript简介 《菜鸟教程》-TypeScript安装 《菜鸟教程》-...

  • TypeScript入门学习@郝晨光

    前言 现在TypeScript越来越火,咱也赶一下潮流,开始学习一下TypeScript,在学习的同时做笔记记录,...

  • 2019-10-16

    https://ts.xcatliu.com/introduction/get-typescript 学习笔记 入...

  • Typescript入门之:接口

    typescript基本使用笔记 安装typescript npm install -g typescript ...

  • Typescript学习笔记(一)

    主要简述官网,方便查找相关参考链接中文官网链接: https://www.tslang.cn/docs/home....

  • typescript学习笔记(一)

    1.ts介绍微软开发的开源编程语言,是js的超集。2.安装 3.运行 4.ts中的数据类型 布尔类型,数字类型,字...

  • TypeScript学习笔记之一初见TypeScript

    一、什么是TypeScript? TypeScript是一种编译性语言、强类型语言、真正的面向对象它是JavaSc...

网友评论

    本文标题:Typescript学习笔记(一)

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