惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
Lohrmann on Cybersecurity
Martin Fowler
Martin Fowler
Engineering at Meta
Engineering at Meta
腾讯CDC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Microsoft Azure Blog
Microsoft Azure Blog
G
Google Developers Blog
TaoSecurity Blog
TaoSecurity Blog
博客园_首页
Vercel News
Vercel News
Hugging Face - Blog
Hugging Face - Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Last Week in AI
Last Week in AI
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
The Exploit Database - CXSecurity.com
量子位
Project Zero
Project Zero
A
Arctic Wolf
小众软件
小众软件
NISL@THU
NISL@THU
C
CERT Recently Published Vulnerability Notes
有赞技术团队
有赞技术团队
MongoDB | Blog
MongoDB | Blog
博客园 - 聂微东
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
N
News and Events Feed by Topic
宝玉的分享
宝玉的分享
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Troy Hunt's Blog
P
Privacy & Cybersecurity Law Blog
Security Latest
Security Latest
B
Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
D
DataBreaches.Net
Schneier on Security
Schneier on Security
The Hacker News
The Hacker News
K
Kaspersky official blog
C
Check Point Blog
Hacker News: Ask HN
Hacker News: Ask HN
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Webroot Blog
Webroot Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
人人都是产品经理
人人都是产品经理
AI
AI
Cisco Talos Blog
Cisco Talos Blog
MyScale Blog
MyScale Blog
Cloudbric
Cloudbric
B
Blog RSS Feed
S
Schneier on Security
P
Palo Alto Networks Blog

oida.dev | TypeScript, Rust

Unsafe for work Tokio: Macros Tokio: Channels Tokio: Getting Started Network Applications on the Tokio Stack Remake, Remodel, Reduce. The `never` type and error handling in TypeScript 5 Inconvenient Truths about TypeScript Refactoring in Rust: Introducing Traits Refactoring in Rust: Abstraction with the Newtype Pattern Announcing the TypeScript Cookbook TypeScript: Iterating over objects The road to universal JavaScript 10 years of oida.dev Rust: Tiny little traits The TypeScript converging point How not to learn TypeScript Getting started with Rust Introducing Slides and Coverage TypeScript: The humble function overload TypeScript + React: Children types are broken TypeScript: In defense of any Rust: Enums to wrap multiple errors Dissecting Deno Error handling in Rust TypeScript: Unexpected intersections Upgrading Node.js dependencies after a yarn audit TypeScript: Array.includes on narrow types TypeScript + React: Typing Generic forwardRefs shared, util, core: Schroedinger's module names Learning Rust and Go TypeScript: Narrow types in catch clauses TypeScript: Low maintenance types Tidy TypeScript: Name your generics Tidy TypeScript: Avoid traditional OOP patterns Tidy TypeScript: Prefer type aliases over interfaces Tidy TypeScript: Prefer union types over enums My new book: TypeScript in 50 Lessons Go Preact! ❤️ this in JavaScript and TypeScript TypeScript and ECMAScript Modules TypeScript + React: Why I don't use React.FC TypeScript + React: Component patterns TypeScript: Augmenting global and lib.dom.d.ts Vite with Preact and TypeScript TypeScript: Union to intersection type 11ty: Generate Twitter cards automatically Are large node module dependencies an issue? TypeScript: Variadic Tuple Types Preview TypeScript: Improving Object.keys Remake, Remodel. Part 4. TypeScript + React: Typing custom hooks with tuple types TypeScript: Assertion signatures and Object.defineProperty TypeScript: Check for object properties and narrow down type Boolean in JavaScript and TypeScript void in JavaScript and TypeScript Symbols in JavaScript and TypeScript Why I use TypeScript TypeScript + React: Extending JSX Elements TypeScript: Validate mapped types and const context TypeScript: Match the exact object shape TypeScript: The constructor interface pattern Streaming your Meetup - Part 4: Directing and Streaming with OBS Streaming your Meetup - Part 3: Speaker audio Streaming your Meetup - Part 2: Speaker video Streaming your Meetup - Part 1: Basics and Projector TypeScript and React Guide: Added a new styles chapter TypeScript and React Guide: Added a new render props chapter TypeScript and React: Styles and CSS TypeScript and React TypeScript and React Guide: Added a new prop types chapter TypeScript without TypeScript -- JSDoc superpowers TypeScript: Mapped types for type maps JAMStack vs serverless web apps The Unsung Benefits of JAMStack Sites TypeScript: Ambient modules for Webpack loaders My most favourite talks in 2018 TypeScript and React Guide: Added a new context chapter TypeScript: Built-in generic types TypeScript: Type predicates JSX is syntactic sugar TypeScript and React Guide: Added a new hooks chapter Getting your CfP application right FAQ on our Angular Connect Talk: Automating UI development TypeScript and Substitutability Debugging Node.js apps in TypeScript with Visual Studio Code From Medium: Deconfusing Pre- and Post-processing From Medium: PostCSS misconceptions Saving and scraping a website with Puppeteer Cutting the mustard - 2018 edition Wordpress as CMS for your JAMStack sites My most favourite podcast episodes in 2017 My most favourite talks in 2017 My most favourite books in 2017 The Best Request Is No Request, Revisited Not so hidden figures - Organizing ScriptConf My podcast journey to ScriptCast Grid layout, grid layout everywhere! #scriptconf and #devone Object streams in Node.js
TypeScript's `erasableSyntaxOnly` Flag
2025-02-03 · via oida.dev | TypeScript, Rust

TypeScript adds a new flag to its compiler with version 5.8: erasableSyntaxOnly. It ensures you won’t use TypeScript features that generate code.

Like enums.

enum Result {
Ok = "Ok",
Error = "Error",
}

// results in

var Result;
(function (Result) {
Result["Ok"] = "Ok";
Result["Error"] = "Error";
})(Result || (Result = {}));

Or Namespaces.

namespace Environment {
let releaseMode: boolean;
}

// results in

(function (Environment) {
let releaseMode;
})(Environment || (Environment = {}));

Or parameter properties in class constructors.

class Person {
constructor(
private name: string,
private age: number
) {}
}

// results in

class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
}

Everything you’re now allowed to do is write stuff that can be removed. A style that lots of people – myself included – always recommended.

I love that Ryan mentions “ideological purists” in the corresponding issue. I’m far from being a purist, let alone an ideological one. But I do recommend to keep TypeScript features to “type syntax” only for a variety of reasons:

  1. No surprises. I have seen countless companies and teams commit heavily to using everything TypeScript has to offer, no questions asked. The result was that they didn’t know what the outcome of their file was in the end. They implemented crucial libraries that were four times the size of what they actually needed just because TypeScript was blowing up their codebase so much.
  2. Stable APIs. Using enums, they created APIs for outside teams that were constantly changing and causing breaking changes. If you expect an enum in a function call but later need to get rid of that enum because of size and performance reasons, the API becomes incompatible with the previous version, even though you most likely pass strings in the final output. A simple string type or subset of string would’ve done the same job and is much more future-proof.
  3. Better compatibility between TypeScript subsets. isolatedModules is a very common flag, and it has some implications for everything that can be globally declaration-merged, like namespaces. If you rely on declaration merged namespaces that generate code (important! There are some that just work on a type level), knowingly or not, you create incompatibility with projects that suddenly require isolatedModules.
  4. Cognitive overhead. TypeScript has so many features that I like to reduce them to a few that get most of the job done. Defining types and annotating types is simple and very effective.

So yeah, you could argue that everything above is “ideological” or comes from a purist’s standpoint. However, it’s important to say that the primary motivator for this change wasn’t any of the ideological reasons the TypeScript team mentions (Those discussions can be very dogmatic, and I love that the team doesn’t give in to those arguments). The main reason was that TypeScript finally landed in Node.js! That’s right; it’s now totally legal to write TypeScript files (with a .ts, .cts, or .mts extension to accommodate the module system of your needs), slap a minimalist tsconfig.json in your project’s root, and run it without any further transpilation step!

// tsconfig.json
{
"compilerOptions": {
"target": "esnext",
"module": "nodenext",
"allowImportingTsExtensions": true,
"rewriteRelativeImportExtensions": true
}
}
// index.mts
import { readFileSync } from "node:fs";

function readFile(path: string): string {
return readFileSync(path).toString();
}

console.log(readFile("index.mts"));

Depending on your editor, you need to install the Node.js types, but all in all, you don’t need anything more. Run node index.mts, and you’re good. However, this feature comes with a little caveat. It only erases type information rather than doing a full transpile. This means that

  1. You need to stick with the features of the EcmaScript version of your Node.js runtime and can’t transpile down to older ES versions.
  2. You can’t use features that generate code. Like experimental decorators, parameter properties in class constructors, namespaces, or enums.

All of those features need to take the code they get and rewrite it into something different. I assume that Node.js simply streams the file’s content and strips away type information on the go, making sure the transpilation step doesn’t severely impact performance.

Personally, I think we’re going to write a lot of TypeScript in the future, which will just be erased. This aligns with the proposal to bring Types as Comments to browsers, and it works well with environments where you write a few lines of JavaScript to automate your tasks, for example.

But see it as a feature that you can opt-in to. I won’t give the dogmatic advice to abolish namespaces and enums. I won’t tell you never to use parameter properties in class constructors. I just tell you what the impact of it is, what my experience with it was, and that I’m happy that there’s a flag that can turn them off if we need to.

Related Articles