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

推荐订阅源

Martin Fowler
Martin Fowler
L
LINUX DO - 最新话题
P
Proofpoint News Feed
Cyberwarzone
Cyberwarzone
Know Your Adversary
Know Your Adversary
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
L
Lohrmann on Cybersecurity
D
Darknet – Hacking Tools, Hacker News & Cyber Security
Security Latest
Security Latest
T
The Exploit Database - CXSecurity.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
P
Privacy & Cybersecurity Law Blog
K
Kaspersky official blog
The Last Watchdog
The Last Watchdog
Webroot Blog
Webroot Blog
Scott Helme
Scott Helme
T
Threat Research - Cisco Blogs
C
Cyber Attacks, Cyber Crime and Cyber Security
WordPress大学
WordPress大学
L
LINUX DO - 热门话题
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - Franky
V
Visual Studio Blog
O
OpenAI News
AI
AI
Hacker News: Ask HN
Hacker News: Ask HN
V2EX - 技术
V2EX - 技术
GbyAI
GbyAI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Simon Willison's Weblog
Simon Willison's Weblog
S
Schneier on Security
Spread Privacy
Spread Privacy
Y
Y Combinator Blog
I
InfoQ
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
F
Fortinet All Blogs
C
CERT Recently Published Vulnerability Notes
T
The Blog of Author Tim Ferriss
C
Check Point Blog
Apple Machine Learning Research
Apple Machine Learning Research
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
N
News and Events Feed by Topic
Project Zero
Project Zero
小众软件
小众软件
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
B
Blog
G
Google Developers 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