返回 Skill 列表
extension
分类: 开发与工程无需 API Key

noimplicitany-completion

在完成TypeScript迁移时使用。在启用严格模式时使用。在最终确定tsconfig时使用。在确保类型安全时使用。在完成采用时使用。

person作者: jakexiaohubgithub

Don't Consider Migration Complete Until You Enable noImplicitAny

Overview

noImplicitAny is the cornerstone of TypeScript's type safety. When disabled, TypeScript silently gives variables the any type when it can't infer a type. This defeats the purpose of TypeScript. Don't consider your migration complete until you've enabled noImplicitAny and eliminated all implicit anys.

When to Use This Skill

  • Finishing TypeScript migration
  • Enabling strict mode
  • Finalizing tsconfig configuration
  • Ensuring type safety
  • Completing TypeScript adoption

The Iron Rule

Enable noImplicitAny to complete your TypeScript migration. Eliminate all implicit anys for full type safety.

Example

// With noImplicitAny: false (default during migration)
function parse(data) {
  // data is implicitly any - no error!
  return data.json();
}

// With noImplicitAny: true
function parse(data) {
  // Error: Parameter 'data' implicitly has an 'any' type
  return data.json();
}

// Fixed with explicit type
function parse(data: string): unknown {
  return JSON.parse(data);
}

Enabling Strict Mode

{
  "compilerOptions": {
    "noImplicitAny": true,
    "strictNullChecks": true,
    "strictFunctionTypes": true,
    "strictBindCallApply": true,
    "strictPropertyInitialization": true,
    "noImplicitThis": true,
    "alwaysStrict": true
  }
}

Reference

  • Effective TypeScript, 2nd Edition by Dan Vanderkam
  • Item 83: Don't Consider Migration Complete Until You Enable noImplicitAny