For example you have a TS app:

enum PaylerPosition {
Guard,
Forward,
Center
} interface Player {
name: string;
position: PlayerPosition;
} let kobe = {
name: 'Kobe',
position: PlayerPosition.Guard
};

The problem for this piece of code is that, you can assign 'kobe' to null, or undefined. And compiler won't catch this error by defualt.

In TypeScritp 2, it includes a new rule:

"strictNullChecks": true

We can set this in tsconfig.json file.

Then it will catch if variable are assigned to 'null' or 'undefined'.

[Typescript 2] Nullable Types - Avoiding null and undefined Bugs的更多相关文章

  1. Angular2入门:TypeScript的类型 - 类型、null、undefined

  2. [TypeScript] Restrict null and undefined via Non-Nullable-Types in TypeScript

    This lesson introduces the --strictNullChecks compiler option and explains how non-nullable types di ...

  3. 浅谈JS中的!=、== 、!==、===的用法和区别 JS中Null与Undefined的区别 读取XML文件 获取路径的方式 C#中Cookie,Session,Application的用法与区别? c#反射 抽象工厂

    浅谈JS中的!=.== .!==.===的用法和区别   var num = 1;     var str = '1';     var test = 1;     test == num  //tr ...

  4. Unity使用可空类型(Nullable Types)

    译林军 范春彦|2014-04-09 09:46|5407次浏览|Unity(375)0 你怎么确定一个Vector3,int,或float变量是否被分配了一个值?一个方便的方式就是使用可空类型! 有 ...

  5. 判断一个值是否为null或者undefined

    var a=null; var b=undefined; if(a===null){ //a==null alert("a=null") }else{ alert("a= ...

  6. null和undefined的一些区别

    读了阮一峰的博客,自己总结一下,便记录一篇博客 在javacript的基本类型中,有2种基本类型,只有1个值,便是null和undefined,都表示的是"无".在一定程度上是相等 ...

  7. JS中判断null、undefined与NaN的方法

    写了个 str ="s"++; 然后出现Nan,找了一会. 收集资料如下判断: 1.判断undefined: 代码如下: <span style="font-siz ...

  8. V8 的 typeof null 返回 "undefined" 的 bug 是怎么回事

    1997 年,IE 4.0 发布,带来的众多新特性中有一个对未来“影响深远”的 DOM API:document.all.在随后的 6 年里,IE 的市场占有率越来越高,直到 2003 年的 95%. ...

  9. 【阿里李战】解剖JavaScript中的 null 和 undefined

    在JavaScript开发中,被人问到:null与undefined到底有啥区别? 一时间不好回答,特别是undefined,因为这涉及到undefined的实现原理.于是,细想之后,写下本文,请各位 ...

随机推荐

  1. 1.2 Use Cases中 Website Activity Tracking官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Website Activity Tracking 网站活动追踪 The origi ...

  2. .vsdc和.svf用于formal verification tools

    svf:Setup Verification for Formality

  3. BingMap频繁Add Pushpin和Delete Pushpin会导致内存泄露

    近期在做性能測试的时候发现BingMap内存泄露(memory leak)的问题,查找了一些国外的帖子,发现也有类似的问题,可是没有好的解决的方法. https://social.msdn.micro ...

  4. iOS_06_Mac os X

    Mac os X 系统简介 * 苹果公司专门为苹果电脑设计的操作系统. * 以坚如磐石的UNIX为基础,既简单易用且功能强大. * x 是一个罗马数字正式的发音位“十”(ten),连续了先前的Mac ...

  5. (转)30 IMP-00019: row rejected due to ORACLE error 12899

    IMP: row rejected due IMP: ORACLE error encountered ORA: value too large , maximum: )导入日志报 IMP: 由于 O ...

  6. Linear to physical address translation with support for page attributes

    Embodiments of the invention are generally directed to systems, methods, and apparatuses for linear ...

  7. HttpClient证书回调问题解决

    /// <summary>        /// httpclient请求        /// </summary>        /// <param name=&q ...

  8. AE 获取地图上当前选中的要素

    樱木 原文 AE开发----获取地图上当前选中的要素 Code1 int selCount = axMapControl1.Map.SelectionCount; IEnumFeature pEnum ...

  9. Yii 错误页面处理

    [错误页面处理] 訪问一个错误的控制器 訪问一个错误的方法 有些控制器和方法禁止訪问   以上訪问会提示错误信息 404  403 以上错误信息是不方便给外边用户看到的. 1. 安全隐患 2. 用户体 ...

  10. javascript进阶教程第三章--匿名和闭包--案例实战

    javascript进阶教程第三章--匿名和闭包--案例实战 一.学习任务 通过几个小练习回顾学过的知识点 二.实例 练习1: 实例描述:打开页面后规定时间内弹出一个新窗口,新窗口指定时间后自动关闭. ...