A literal type is a type that represents exactly one value, e.g. one specific string or number. You can combine literal types with union types to model a finite set of valid values for a variable. In this lesson, we explore the all kinds of literal t…
基础数据类型(Basic Types) 为了搭建应用程序,我们需要使用一些基础数据类型比如:numbers,strings,structures,boolean等等. 在TypeScript中除了JavaScript现有的常见的数据类型外还有一个非常实用的枚举类型(enumeration type). Boolean 最基础的数据类型莫过于只有true和false的布尔类型了,在TypeScript,JavaScript以及其它的很多数程序语言中我们使用关键字'boolean'. var isD…
If Typescript is the first language in which you've encountered generics, the concept can be quite difficult to understand. We skip the lecture in this lesson and dive straight into a real-world use-case that is guaranteed to help you understand the…
该文章用于督促自己学习TypeScript,作为学笔记进行保存,如果有错误的地方欢迎指正 2019-03-27  16:50:03 一.什么是TypeScript? TypeScript是javascript的超集,在ts中可以使用所有的js代码,并对js进行了扩展,包括类型效验,数据类型,接口等 如图所示,TypeScript包含了javascript并进行延伸 二.准备工作 在说TypeScript之前先说一下如何让ts编译为js代码 首先安装 typescrpt, npm install…
We usually think of types as something that can define a single layer of an object: with an interface we normally specify a list of a few properties and their respective types. If any one of those properties is another object we must refer again to i…
Some functions may have different return types depending on the types of the arguments with which they’re invoked. Using TypeScript’s function overloads, you can create an overload for each allowed combination of parameter and return types. This way,…
Typescript classes make traditional object oriented programming easier to read and write. In this lesson we learn about class syntax, what the constructor is and some interesting variable features. interface Opponent { health: number; alias: string;…
前言 在第一篇中,我们简单介绍了TypeScript的一些简单语法,那么如果我们只是简单使用TypeScript开发一个web项目,应该做哪些准备?接下来我们就结合TypeScript和Webpack来创建一个基于TypeScript的Web应用程序. 准备工作 为了创建第一个Web应用,我们先做一些基本的准备工作,需要安装以下依赖: webpack webpack-cli webpack-dev-server webpack-merge html-webpack-plugin clean-we…
启动项目 Express 是一个nodejs框架,用于构建Web后端应用程序.它非常的灵活,你可以用你喜欢的方式去使用他.在这个系列文章里,记录了我使用typescript express去构建一个web api项目的方法. 首先我们需要使用NPM安装一些必要的包: npm init npm install typescript ts-node --D npm install express --save 接下来我们创建一个配置文件tscofig.json放置在根目录: { "compilerO…
To using decorate, we can modifiy tsconfig.json: { "compilerOptions": { ... "experimentalDecorators": true, ... } } So for example we want to build a '@LogMethod' decorator, which arroding to the system logging level to decide whether…