跳到正文
Skillpedia
通用编程75k · #3068

typescript-strict-mode

它能做什么

这项技能检查 TypeScript 项目的设置,并开启严格的类型检查。适用于希望编译器在代码运行前捕捉更多错误的开发者。

适用场景

  • ✓当 TypeScript 项目的 tsconfig.json 中没有严格模式设置的时候。
  • ✓当代码库中出现空值错误或隐式 any 类型的时候。
  • ✓当你开始新的 TypeScript 项目,并选择最安全的设置的时候。

技能链接

https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/typescript-strict-mode/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/typescript-strict-mode/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我有一个 TypeScript 项目。请检查我的 tsconfig,如果安全的话就开启严格模式。”

每周 5 个新技能,1 分钟读完。

工作原理

智能体会读取 tsconfig 文件,并检查哪些严格选项已开启。它会开启缺少的选项;如果现有代码有很多错误,则会逐步启用。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

Enable TypeScript strict mode in tsconfig.json

Without strict mode, TypeScript allows implicit any types, ignores possible null/undefined values, and silently accepts unsound function assignments — meaning the type system gives a false sense of safety. Enabling strict mode makes TypeScript catch the bugs it was designed to prevent, turning type errors into compile-time failures rather than runtime surprises in production.

Quick Reference

  • "strict": true enables strictNullChecks, noImplicitAny, and six other checks
  • Enable strict from project start — retrofitting a large codebase is painful
  • On existing projects: enable strictNullChecks first, then other flags incrementally
  • Strict mode eliminates entire classes of null reference and implicit-any bugs

Check

Inspect the tsconfig.json in this project and report whether "strict": true (or individual strict flags) is enabled. List any missing strict flags.

Fix

Add "strict": true to the compilerOptions in tsconfig.json. If the project has existing type errors, explain how to enable strictNullChecks first as a stepping stone.

Explain

Explain what TypeScript strict mode enables, which individual flags it activates, and why each flag matters for catching real bugs.

Code Review

Check whether the codebase relies on implicit any, unchecked null access, or loose function type assignments that strict mode would reject. Flag the specific patterns and show what stricter types would look like.


For full implementation details, code examples, and framework-specific guidance, see references/rule.md.

Rule page: https://frontendchecklist.io/rules/javascript/typescript-strict-mode

常见问题

严格模式会开启什么?

它会启用一组检查,包括 strictNullChecks 和 noImplicitAny,用于捕捉常见错误。

如果我的项目有很多类型错误怎么办?

这项技能建议先启用 strictNullChecks,然后再逐个开启其他选项。

从一开始就开启严格模式更容易吗?

这项技能指出,从一开始就开启严格模式,比之后为大型项目补做要容易得多。

详情

作者的原始描述

Use when setting up a new TypeScript project, auditing an existing tsconfig.json, or reviewing code where null-reference errors or implicit any types are present.

repo: thedaviddias/Front-End-Checklist

热度

GitHub 星标
75k
排名
#3068
许可证
MIT
更新时间
2026/10/31

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能