话题编程语言 › TypeScript

编程语言:TypeScript

抛砖引玉:TypeScript 从入门到实践

众所周知 JavaScript 是一门弱类型语言,在前端进入工程化后,代码仓库越来越大,JavaScript 弱类型的缺点被无限放大,使其难以胜任开发大型项目。在一个多人维护的项目中,往往不知道别人写的函数是什么意思、需要传入什么参数、返回值是什么,一个用法不小心就会导致线上出现 BUG,所以除了靠口口相传以外还要维护大量的代码注释或者接口文档来提供其他人了解。但是当我们使用 TypeScript 后,除了初期具有一定的学习成本以外,基本上可以很好的解决上述的问题。

【TypeScript】never 和 unknown 的优雅之道

TypeScript 在版本 2.0 和 3.0 分别引入了 “never” 和 “unknown” 两个基本类型,在引入这两个类型之后,TypeScript 的类型系统得到了极大的完善。

淘宝店铺 TypeScript 研发规约落地实践

淘宝店铺前端团队的稳定性治理第一步,通过全流程研发规约的建立,让TypeScript成为大型前端工程的一剂良药。

TypeScript 类型编程: 从基础到编译器实战

本文假定读者已经使用过 typescript 并且了解基础的类型概念,不会介绍基础概念,主要专注于介绍如何进行系统化的类型编程。示例主要来源于官网、类型挑战仓库以及日常开发。

Etsy’s Journey to TypeScript

Over the past few years, Etsy’s Web Platform team has spent a lot of time bringing our frontend code up to date. It was only a year and a half ago that we modernized our Javascript build system in order to enable advanced features, things like arrow functions and classes, that have been added to the language since 2015. And while this upgrade meant that we had futureproofed our codebase and could write more idiomatic and scalable Javascript, we knew that we still had room for improvement.

Etsy has been around for over sixteen years. Naturally, our codebase has become quite large; our monorepo has over seventeen thousand JavaScript files in it, spanning many iterations of the site. It can be hard for a developer working in our codebase to know what parts are still considered best practice, and which parts follow legacy patterns or are considered technical debt. The JavaScript language itself complicates this sort of problem even further — in spite of the new syntax features added to the language over the past few years, JavaScript is very flexible and comes with few enforceable limitations on how it is used. This makes it notoriously challenging to write JavaScript without first researching the implementation details of any dependencies you use. While documentation can help alleviate this problem somewhat, it can only do so much to prevent a JavaScript library from being used improperly, which can ultimately lead to unreliable code.

All of these problems (and many more!) were ones that we felt TypeScript might be able to solve for us. TypeScript bills itself as a “superset of Javascript.” In other words, TypeScript is everything in Javascript with the optional addition of types. Types, in programming, are basically ways to declare expectations about the data that moves through code: what kinds of input can be used by a function, what sorts of values a variable can hold. (If you’re not familiar with the concept of types, TypeScript’s handbook has a fantastic introduction.) TypeScript is designed to be easily adopted incrementally in existing Javascript projects, particularly in large codebases where shifting to a new language can be an impossibility. It is exceptionally good at inferring types from the code you’ve already written, and it has a type syntax nuanced enough to properly describe all of the quirks that are common in Javascript. Plus, it’s developed by Microsoft, it’s already in use at companies like Slack and AirBnB, and is by far the most used and loved flavor of Javascript according to last year’s “State of JS” survey. If we were going to use types to bring some amount of order to our codebase, TypeScript seemed like a really solid bet.

This is why, hot on the heels of a migration to ES6, we started investigating a path to adopting TypeScript. This post is all about how we designed our approach, some of the fun technical challenges that resulted, and what it took to educate an Etsy-sized company in a new programming language.

用 TypeScript 类型运算实现一个中国象棋程序

众所周知,TypeScript 是图灵完备的,因此,只要我们愿意,那当然是可以用它来实现一个象棋程序的。于是我们就快乐地开始了,为了理解方便,我们不考虑性能优化策略,纯粹从功能实现角度去构建。另外,我们尝试用中文来编写这个程序,因为类型运算中需要用到的操作符很少,类型本质上是一种对现实世界的描述,某种程度上算是一种业务描述语言,使用中文也挺好的。

如何优雅地在React 中使用TypeScript,看这一篇就够了!

在单独使用 TypeScript 时没有太多的坑,不过和React结合之后就会复杂很多。本文就来聊一聊TypeScript与React一起使用时经常遇到的一些类型定义的问题。

浅谈 Typescript(三):两个空间的交流

长久以来,JS 依靠着运行时把变量拉出来,小心翼翼判断类型,生怕调出 Uncaught TypeError: Cannot read property 'foo' of undefined 或者 Uncaught TypeError: foo.slice is not a function ,然后白屏了。TS 出现后,终于有人在开发和编译阶段就管管 JS 变量的类型。

一文速览 TypeScript 装饰器 与 IoC 机制

你真的了解 TypeScript 装饰器吗?本文带你从它的诞生一路聊到原理应用。

玩转TypeScript工具类型(下)

本文是《玩转TypeScript工具类型》系列的最后一篇。

玩转TypeScript工具类型(中)

本文是《玩转 TypeScript工具类型》系列的第二篇。

TypeScript是如何工作的

TypeScript 能让我们在开发时发现程序中类型定义不一致的地方,及时消除隐藏的风险,大大增强了代码的可读性以及可维护性。本文就来探讨简单探讨一下 TypeScript 是如何工作的,以及有哪些工具帮助它实现了这个目标。

玩转TypeScript工具类型(上)

多人协同开发已经成为了前端开发的标配,这是业务驱动下的技术进步。

前端也要懂图形学:使用 TypeScript 实现光线追踪

结合计算机图形学来讲解 TypeScript。

TypeScript 声明文件全解析

全面拥抱 TS 的时代,TS 已经成为日常开发中的重要部分。本文主要介绍 TS 声明文件的写法。

LRC 格式以及如何使用 TypeScript 解析

LRC 是一种常见的歌词保存格式, 使用文本的形式保存。

首页 - Wiki
Copyright © 2011-2023 iteam. Current version is 2.115.2. UTC+08:00, 2023-06-02 20:07
浙ICP备14020137号-1 $访客地图$