Say you have an array that has at least one item repeated. How would you find the repeated item. This is a question commonly presented to beginner developers. Here we discuss the elegant solution to this problem. export function repeatedItem<T>(arra…
Functor composition is a powerful concept that arises when we have one Functor nested in another Functor. It becomes even more powerful when both of those are Chains, allowing us to apply each Functor’s special properties and effects for a given comp…
Conditional types take generics one step further and allow you to test for a specific condition, based on which the final type will be determined. We will look at how they work on a basic level and then leverage their power to allocate function types…
The keyof operator produces a union type of all known, public property names of a given type. You can use it together with lookup types (aka indexed access types) to statically model dynamic property access in the type system. Take away: 1. extends 2…
As of TypeScript 2.4, it is now possible to define string enums, or more precisely, enums with string members. Just like any other numeric enum, string enums can be made constant using the const modifier so that they disappear entirely from the gener…
Using Object Oriented Programming, OOP, style allows us to apply Inversion of Control, IoC, and more patterns. An IoC container helps decoupling dependencies by using a class constructor or properties to identify and inject its dependencies. This les…
前言 在第二小节中,我们讨论了利用TypeScript创建Web项目的实现,在本下节,我们讨论一下如何结合React创建一个具备TypeScript类型的应用项目. 准备 Webpack配置在第二小节项目的基础上做了一些修改, 添加React相关依赖:react.react-dom.@types/react 和@types/react-dom 修改Webpack配置文件 修改webpack.base.config.js,其余文件和第二小节保持一致,修改如下: const HtmlWebpackP…
//move the repeated item            NSInteger index = [orignalArray count] - 1;            for (id object in [orignalArray reverseObjectEnumerator]) {                if ([orignalArray indexOfObject:object inRange:NSMakeRange(0, index)] != NSNotFound)…
使用Typescript来写javascript 前几天尝试使用haxejs来写javascript,以获得静态类型带来的益处.虽然成功了,但很快发现将它与angularjs一起使用,有一些不太顺畅的地方,导致开发效率没有提升,反而下降了.虽然我认为使用haxejs来写普通的js(或者与jquery相关的js)没有问题,但不适合与angularjs这样与HTML侵入较大的js框架配合. 昨天偶然发现idea居然支持typescript了,于是打算尝试一下typescript,目前的感觉还不错,相…
什么是 TypeScript TypeScript 是 JavaScript 的类型的超集,它可以编译成纯 JavaScript. 安装 TypeScript 命令行工具安装: npm install -g typescript 编译一个 TypeScript 文件: tsc hello.ts 原始数据类型/ 任意值 为每一个变量提前申明该类型,则该变量取值只能为申明的类型,否则报错 如果一个变量可以任意取值,可以通过any 申明该变量为任意值 原始数据类型包括:布尔值(boolean).数值(…