🟦 TypeScript 格式化TypeScript Formatter
用 Prettier 美化 TypeScript / TSX 代码:统一缩进、引号和分号,支持类型注解、泛型、装饰器和 JSX,语法错误提示行列号,代码不上传。Beautify TypeScript/TSX with Prettier — consistent indentation, quotes and semicolons, with support for types, generics, decorators and JSX, plus line/column syntax errors. Code never leaves your browser.
使用说明与常见问题How-to & FAQ
「TypeScript 格式化」是什么?What is the TypeScript Formatter tool?
用 Prettier 美化 TypeScript / TSX 代码:统一缩进、引号和分号,支持类型注解、泛型、装饰器和 JSX,语法错误提示行列号,代码不上传。Beautify TypeScript/TSX with Prettier — consistent indentation, quotes and semicolons, with support for types, generics, decorators and JSX, plus line/column syntax errors. Code never leaves your browser.
如何使用「TypeScript 格式化」?How do I use the TypeScript Formatter tool?
在「TypeScript 格式化」中,把内容粘贴或输入到上方输入框,按需设置「缩进」、「行宽」,结果会实时显示在下方,点击「复制结果」即可复制。例如输入「const a:number=1;function f(x:string){return x}」,得到「const a: number = 1; ⏎ function f(x: string) { ⏎ return x; ⏎ }」。In the TypeScript Formatter: Paste or type into the input box, adjust "Indent", "Print width"; the result appears below instantly — click "Copy result" to copy it. Example: "const a:number=1;function f(x:string){return x}" → "const a: number = 1; ⏎ function f(x: string) { ⏎ return x; ⏎ }".
支持 TSX / JSX 吗?Does it support TSX/JSX?
支持,Prettier 的 TypeScript 解析器可以处理 TSX 语法;装饰器、泛型、枚举、命名空间等语法也都支持。Yes — Prettier's TypeScript parser handles TSX, and decorators, generics, enums and namespaces are supported too.
为什么第一次比较慢?Why is the first run slower?
TypeScript 解析器较大(约 1.1 MB),只在第一次格式化时按需加载,之后会被浏览器缓存。The TypeScript parser is large (about 1.1 MB), so it is loaded only on first use and then cached by the browser.
会检查类型错误吗?Does it type-check?
不会,格式化只检查语法,不做类型检查(那需要完整的 TypeScript 编译器和项目配置)。No — formatting checks syntax only; type checking needs the full TypeScript compiler and your project config.
代码或数据会被上传吗?Is my code or data uploaded?
不会。「TypeScript 格式化」完全用 JavaScript 在本地运行,适合处理含有密钥、内部接口等敏感内容的数据。No. The TypeScript Formatter runs entirely in local JavaScript, so it is safe for data containing keys or internal endpoints.
「TypeScript 格式化」免费吗?需要注册吗?Is the TypeScript Formatter free? Do I need an account?
「TypeScript 格式化」完全免费,无需注册或安装,打开网页即可使用,手机和电脑都能用;输入的内容只在你的浏览器本地处理。The TypeScript Formatter is completely free with no sign-up or install and works on phones and desktops; what you enter is processed only in your browser.