话题编程语言 › TypeScript


TypeScript 前端工程最佳实践

本文介绍了在前端业务开发中使用TypeScript的基本用法和常用知识点。作者提到了TypeScript的类型系统复杂,但可以帮助开发人员编写更好、更安全的代码。文章还介绍了一款VSCode插件——Paste JSON as Code,可以自动生成接口类型定义的TypeScript代码,提高开发效率。总结完毕。

携程度假基于 RPC 和 TypeScript 的 BFF 设计与实践

一种基于 RPC 的 BFF 实践,显著提升接口调用的效率和类型安全。



TypeScript 基础学习之泛型和 extends 关键字

泛型是指在定义函数、接口或类的时候,不预先指定具体类型,而是在使用的时候再指定类型;extends 关键字主要用法,就是继承类型,结合三元表达式来完成更多的类似函数的应用方法。

TypeScript magic

At Artsy, we love TypeScript. We use it in most of our node/web/mobile repos. Today, I want to talk about a specific case we found while trying to make our types more strict on palette-mobile, which is our Design System for React Native.

使用 TypeScript 定义业务字典

在业务开发中,我们常常需要定义一些枚举值。随着业务逻辑的扩展,简单的枚举值往往会衍生出许多关联的字段定义。面对需要定义复杂业务字典的场景,本文将使用 TypeScript 实现一个定义业务字典的工具函数,并且支持类型提示。

DeepKit —— 赋予 TypeScript 更多可能性

一个叫 Deepkit 的第三方库,可以将 TypeScript 的类型信息保留到运行时进行消费。

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

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

【TypeScript】never 和 unknown 的优雅之道

TypeScript 在版本 2.0 和 3.0 分别引入了 “never” 和 “unknown” 两个基本类型,在引入这两个类型之后,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 装饰器吗?本文带你从它的诞生一路聊到原理应用。

首页 - Wiki
Copyright © 2011-2024 iteam. Current version is 2.123.1. UTC+08:00, 2024-03-01 21:57
浙ICP备14020137号-1 $访客地图$