this is probably the most tricky thing to use in JavaScript and therefore TypeScript. Fortunately there is a TypeScript compiler flag noImplicit this that can help catch unsafe usages so beginners don't get caught off guard. // tsconfig.json { "compi…
It’s easy to pass the wrong value to a function. Typescript interfaces are great because they catch errors at compile time or in an IDE. In this lesson we’ll learn how to describe a type shape with Typescript interfaces. Using interface to describe a…
In JavaScript, many libraries use string arguments to change behavior. In this lesson we learn how Typescript catches string related errors at compile time by assigning a string literal as a type. type whiteList = "DOG" | "CAT" | "…
Sometimes we want our function arguments to be able to accept more than 1 type; e.g. a string or an array. This lesson will show us how to assign more than 1 type to a variable with Typescript union types and type aliases. type types = string | boole…
Sometimes the compiler needs help figuring out a type. In this lesson we learn how to help out the compiler with Typescript type assertion. We have a SuperHero and a BadGuy. Let's make a function that saves the day if the function's argument is a Sup…
Typescript classes make inheritance much easier to write and understand. In this lesson we look into how to set up inheritance with Typescript classes, extends and super. class ComicBookCharacter ( constructor{ public alias: string, public health: nu…
The postshows you how to use the null coalescing operator (??) instead of logical or (||) to set default values in TypeScript 3.7 to prevent expected bugs in your code. ; const correct = (val !== undefined && val !== null) ? val : 0.5; // const in…
写在前面 作者并没有任何可以作为背书的履历来证明自己写作这份手册的分量. 其内容大都来自于TypeScript官方资料或者搜索引擎获得,期间掺杂少量作者的私见,并会标明. 大部分内容来自于http://www.infoq.com/minibooks/typescript-c-sharp-programmers 你甚至可以认为这就是对这本英文小册子的翻译,实际上80%如此. 写给那些已经有编程基础,尤其是掌握c语言.c#.java这一类型的静态类型语言的同好. 鸣谢 先谢国家,虽然并不知道要谢些什…
typescript指南 前言 typescript是angularjs2推荐使用的脚本语言.它由微软2012年首次发布. 一.    typescript和javascript的区别 1.从遵循的规范上的角度: Javascript遵循ECMA5的规范,TypeScript是语法上对ECMA6的实现. 2.从功能上说: TypeScript提供了类.模块和接口来帮助构建组件,更方便写面向对象的程序,所以被称为更好的typescript. 3.从支持上说: 所有的浏览器都支持ES5及之前的jav…
环境准备 .Net Core 版本:下载安装.Net Core SDK,安装完成之后查看sdk版本 ,查看命令dotnet --version,我的版本是2.2.101 IDE: Visual Studio 2017 目标:将 我的GitHub项目 Captcha.WebApi 改造,在项目中使用TypeScript 运行环境准备 安装Node.js 如果已经安装请忽略,https://nodejs.org/zh-cn/ 下载nodejs,我选择的是LTS版本. 安装完成之后验证是否安装成功.c…